1

Is there a way to access the css, specifically the width, of an element using VB.net? I am trying to use the width as a variable in VB but I'm having trouble finding it using the class attribute of the div I want

3
  • Could you please post an example of what you are trying to do? Commented Aug 21, 2012 at 19:07
  • The width of my div is set to "inherit" in css and I need to access the exact width of the div based on the window size as it is a responsive design Commented Aug 21, 2012 at 19:14
  • Are you using ASP.net, or is the VB you're talking about executing some sort of client-application to host web pages? Commented Aug 21, 2012 at 19:24

2 Answers 2

1

If I'm reading your question correctly: you'll need to have the 'runat="server"' attribute added to your HTML tag on your page. For example:

<div id="divTest" runat="server">Test Me</div>

In your code behind:

dim myDiv = Ctype(Me.Page.FindControl("divTest"), System.Web.UI.HtmlControls.HtmlGenericControl)
myDiv.Style.Add("color", "#ff0000")

You can add a style as shown, or just simply access it to find the current set value:

div.Style("width")

Of course, if you are using master pages you will have to drill down with FindControl() from your uppermost masterpage.

Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure how you are accessing a webElement. I am assuming that this is done by either internet control library or by IE browser control.

For Internet control library you can use. This interface is available in MSHTML library DLL.

You can determine the location, width, and height of an object by using a combination of the IHTMLElement::offsetLeft, IHTMLElement::offsetTop, IHTMLElement::offsetHeight, and IHTMLElement::offsetWidth properties. These numeric properties specify the physical coordinates and dimensions of the object relative to the object's offset parent.

Or just go to this place to find the information about measuring WebElements specifics Here

I would request you to explain your problem in a bit more detail.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.