Get actual limits of html element in c #

I need to get the actual number of pixels that the IHTMLElements marker occupies in my C # code. I looked at the style and currentStyle elements in it, but the relevant parts are either null or set to "auto".

A web search showed the getCurrentStyle function in javascript, but I need these numbers in my C # code.

Obviously I'm a bit new to js and html and that's it ...

So, is there a way to get the actual calculated number of pixels used for a field of elements (or any other one) in C # code?

I forgot to add: this will only be used in Internet Explorer for the foreseeable future

+1


a source to share


3 answers


Does it have to be in C # code? This may be easier to do on the client via a script - for example jQuery some combination of width () , innerWidth () and outerWidth () should return a field.



+1


a source


Javascript section

var elementToCalc = document.getElementById ("your element");

document.getElementById('txtHidMarginTop').value = parseInt ( elementToCalc.currentStyle.marginTop );
document.getElementById('txtHidMarginLeft').value = parseInt ( elementToCalc.currentStyle.marginLeft;
document.getElementById('txtHidMarginRight').value = parseInt ( elementToCalc.currentStyle.marginRight;
document.getElementById('txtHidMarginBottom').value = parseInt ( elementToCalc.currentStyle.marginBottom );

      

HTML section



<input type='hidden' id='txtHidMarginTop' runat='server' />
<input type='hidden' id='txtHidMarginLeft' runat='server' />
<input type='hidden' id='txtHidMarginBottom' runat='server' />
<input type='hidden' id='txtHidMarginRight' runat='server' />

      

Attach these variables to type = 'hidden' using runat = 'server' and then you can access this variable in C # using the DOM's Value property.

C # Secition

 string marginTop = int.Parse ( txtHidMarginTop.Value );
    string marginLeft = int.Parse ( txtHidMarginLeft.Value );
    string marginRight = int.Parse ( txtHidMarginRight.Value );
    string marginBottom = int.Parse ( txtHidMarginBottom.Value );

      

0


a source


How about subtracting the IHTMLElement2.clientWidth value from offsetWidth?

More about metrics: http://msdn.microsoft.com/en-us/library/ms530302(v=vs.85).aspx

0


a source







All Articles