Testing control propertieshttp://forums.asp.net/t/1385571.aspx/1?Testing+control+propertiesMon, 06 Apr 2009 03:58:45 -040013855712944907http://forums.asp.net/p/1385571/2944907.aspx/1?Testing+control+propertiesTesting control properties <p>Is there a way to test if a control in enabled or disabled, background colors etc? So if I grab a &lt;asp:imagebutton control and I tell if it is enabled?<font size="2"></p> </font> 2009-02-16T15:20:14-05:002945082http://forums.asp.net/p/1385571/2945082.aspx/1?Re+Testing+control+propertiesRe: Testing control properties <p>Hey Srhone,</p> <p>These are all attributes that get added to the rendered html tag (disabled=&quot;disabled&quot; for instence).&nbsp; You will need to get a collection of the attributes (HtmlElementAttributeReader) for that element and then verify using those. Bellow is some code showing how to get the HtmlElementAttributeReader for an element.</p> <pre class="code"><span style="color:#2b91af">HtmlPage </span>page = <span style="color:blue">new </span><span style="color:#2b91af">HtmlPage</span>(<span style="color:#a31515">&quot;SomePage.aspx&quot;</span>); <span style="color:#2b91af">HtmlElement </span>element = page.Elements.Find(<span style="color:#a31515">&quot;ControlID&quot;</span>); <span style="color:#2b91af">HtmlElementAttributeReader </span>reader = element.GetAttributes(); <span style="color:green">//Some common attributes are strongly typed properties </span><span style="color:#2b91af">Assert</span>.AreEqual(<span style="color:#a31515">&quot;Expected&quot;</span>, reader.Class); <span style="color:green">//Other attributes are indexed through the collection </span><span style="color:#2b91af">Assert</span>.AreEqual(<span style="color:#a31515">&quot;Expected&quot;</span>, reader[<span style="color:#a31515">&quot;disabled&quot;</span>]);</pre> 2009-02-16T17:18:07-05:003044242http://forums.asp.net/p/1385571/3044242.aspx/1?Re+Testing+control+propertiesRe: Testing control properties <p>So this method only appears to work for a small number of properties.</p> <p>Can you give an working example on how to find the property: naturalWidth&nbsp; inside of an Image Element?</p> <p>&nbsp;</p> <p>Additionally, does any one have a clever way to use attributes to scan all the images on a page and see if they are loaded? I read that the naturalWidth will be set to 0 when an image doesn't load .. so I am trying to get that working.</p> 2009-03-28T02:29:41-04:003045454http://forums.asp.net/p/1385571/3045454.aspx/1?Re+Testing+control+propertiesRe: Testing control properties <p>&nbsp;I am not familiar with the &quot;naturalWidth&quot; attribute. You are saying that this attribute exists on the HTML DOM but you can't get to it when you do imageElement.GetAttributes() ? If so, then this sounds like a bug that we should to take a look at that.</p> <p>- Federico <br> </p> 2009-03-28T20:00:48-04:003053227http://forums.asp.net/p/1385571/3053227.aspx/1?Re+Testing+control+propertiesRe: Testing control properties <p>So using Chrome - Inspect Element on an Image .. you can see the HTMLImageElement has a set of properties:</p> <p><a href="http://lh3.ggpht.com/_Y8FtTHDiOgY/SdKr_9Ol4ZI/AAAAAAAAAMM/YGjbra_plDM/s1024/Image_Properties.JPG">http://lh3.ggpht.com/_Y8FtTHDiOgY/SdKr_9Ol4ZI/AAAAAAAAAMM/YGjbra_plDM/s1024/Image_Properties.JPG</a></p> <p>&nbsp;</p> <p>Also here is a web article talking about how to check naturalHeight using JavaScript:</p> <p><a href="http://javascript.royh.cn/img/naturalheight-2-0-naturalwidth.html">http://javascript.royh.cn/img/naturalheight-2-0-naturalwidth.html</a></p> 2009-03-31T23:52:56-04:003065040http://forums.asp.net/p/1385571/3065040.aspx/1?Re+Testing+control+propertiesRe: Testing control properties <p>Thanks! I've logged a bug for this. We'll look at it for the next refresh.</p> <p>- Federico <br> </p> 2009-04-06T00:01:10-04:003065260http://forums.asp.net/p/1385571/3065260.aspx/1?Re+Testing+control+propertiesRe: Testing control properties <p>Thanks alot.&nbsp; For reference here is another attempt to link images from my stupid google account.</p> <table class="" style="width:auto"> <tbody> <tr> <td class=""><a href="http://picasaweb.google.com/lh/photo/vz3MPWWDrE96hMs1thHJcQ?feat=embedwebsite"><img src="http://lh3.ggpht.com/_Y8FtTHDiOgY/SdKr_9Ol4ZI/AAAAAAAAAMM/YGjbra_plDM/s144/Image_Properties.JPG"></a></td> </tr> <tr> <td class="" style="font-size:11px; font-family:arial,sans-serif; text-align:right"> From <a href="http://picasaweb.google.com/hawthorn/WebPostings?feat=embedwebsite"> Web Postings</a></td> </tr> </tbody> </table> <p>&nbsp;</p> 2009-04-06T03:58:45-04:00