<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://aspadvice.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>C# Nuggets : xhtml, expando</title><link>http://aspadvice.com/blogs/rbirkby/archive/tags/xhtml/expando/default.aspx</link><description>Tags: xhtml, expando</description><dc:language>en</dc:language><generator>CommunityServer 2.1 (Build: 60809.935)</generator><item><title>Client-side validation in Firefox</title><link>http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx</link><pubDate>Wed, 01 Nov 2006 07:49:00 GMT</pubDate><guid isPermaLink="false">e709ad4c-0c15-48eb-915e-c462c6e85445:23784</guid><dc:creator>rbirkby</dc:creator><slash:comments>34</slash:comments><comments>http://aspadvice.com/blogs/rbirkby/comments/23784.aspx</comments><wfw:commentRss>http://aspadvice.com/blogs/rbirkby/commentrss.aspx?PostID=23784</wfw:commentRss><description>&lt;p&gt;Recently, I was faced with a problem whereby client-side validation of controls failed to work in &lt;a href="http://www.mozilla.org/"&gt;Firefox&lt;/a&gt;. Only server-side validation was working. Client side validation was working fine in IE.&lt;/p&gt;&lt;p&gt;This was puzzling as everything I read said that ASP.Net v2 supported client-side validation in Firefox. No amount of Googling helped to identify the problem, so I had to track it down from scratch - and the results were quite interesting. If you have &lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;xhtmlConformance&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;
&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:red;"&gt;mode&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;=&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;quot;&lt;span style="color:blue;"&gt;Legacy&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;set in your web.config, then client-side validation is disabled in firefox. &lt;/p&gt;&lt;p&gt;To see why, we have to jump down into the validation framework that ASP.Net sends to the web browser. The actual Javascript validation function looks like:

&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;function&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;
ValidatorValidate(val) { &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;val.isvalid = &lt;span style="color:blue;"&gt;true&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt;
(val.enabled != &lt;span style="color:blue;"&gt;false&lt;/span&gt;) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color:blue;"&gt;if&lt;/span&gt; (&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(val.evaluationfunction) == &lt;span style="color:maroon;"&gt;&amp;quot;function&amp;quot;&lt;/span&gt;) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;val.isvalid =
val.evaluationfunction(val); &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ValidatorUpdateDisplay(val);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;}&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;Using &lt;a href="http://www.mozilla.org/projects/venkman/"&gt;Venkman&lt;/a&gt;, I was able to see that val.evaluationfunction wasn&amp;#39;t a function at all, therefore the page wasn&amp;#39;t getting validated because of this. A bit more searching found that this evaluationfunction is an expando attribute. In ASP.Net v1, this expando is an IE-only HTML expando, defined directly in the HTML markup. In ASP.Net v2, this is a Javascript expando attribute, defined on the DOM via Javascript, and therefore compatible with both IE and Firefox. &lt;/p&gt;&lt;p&gt;For example, the &lt;a href="http://msdn2.microsoft.com/en-us/system.web.ui.webcontrols.requiredfieldvalidator.aspx"&gt;RequiredFieldValidator&lt;/a&gt; calls &lt;a href="http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerexpandoattribute.aspx"&gt;RegisterExpandoAttribute&lt;/a&gt;. You can call this method yourself like:&lt;br /&gt;

&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;Page.ClientScript.RegisterExpandoAttribute(TextBox1.ClientID,
&lt;span style="color:maroon;"&gt;&amp;quot;value&amp;quot;&lt;/span&gt;, TextBox1.Text);&lt;/span&gt;&lt;/p&gt;



&lt;p&gt;&amp;nbsp;This produces a block of Javascript just before the closing &lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;form&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;gt;&lt;/span&gt; tag like:&lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;script&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; &lt;span style="color:red;"&gt;type&lt;/span&gt;&lt;span style="color:blue;"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;&amp;lt;!--&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;var&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt; TextBox1 =
document.all ? document.all[&lt;span style="color:maroon;"&gt;&amp;quot;TextBox1&amp;quot;&lt;/span&gt;]
: document.getElementById(&lt;span style="color:maroon;"&gt;&amp;quot;TextBox1&amp;quot;&lt;/span&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';"&gt;TextBox1.value
= &lt;span style="color:maroon;"&gt;&amp;quot;&amp;quot;&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:green;"&gt;// --&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;script&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/p&gt;

&lt;p class="MsoNormal"&gt;where &amp;quot;value&amp;quot; has become the new expando attribute. In the case of the RequiredFieldValidator, the expando name is&amp;quot; evaluationfunction&amp;quot; and it is added to the &lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;span&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;gt; &lt;/span&gt;representing the control at runtime. &lt;br /&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;It turned out that this block of Javascript wasn&amp;#39;t being sent to Firefox in my situation, and I didn&amp;#39;t know why. Instead, the evaluationfunction expando attribute was being rendered directly on the&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt; &amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;span&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;gt; &lt;/span&gt;element in HTML.&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;So after good deal of decompilation using &lt;a href="http://www.lutzroeder.com/"&gt;Reflector&lt;/a&gt;, and debugging using Reflection Invokeing of private methods, I discovered the problem was that RegisterExpandoAttribute checks the &lt;a href="http://msdn2.microsoft.com/en-US/library/ms178159.aspx"&gt;XHTML Rendering Mode&lt;/a&gt; prior to generating the Javascript and if that rendering mode is set to &lt;a href="http://msdn2.microsoft.com/en-us/library/ms228268.aspx"&gt;Legacy&lt;/a&gt;, then the expando is rendered directly onto the &lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:maroon;"&gt;span&lt;/span&gt;&lt;span style="font-size:10pt;font-family:'Courier New';color:blue;"&gt;&amp;gt;&lt;/span&gt; element and no Javascript code is rendered. The result of this is to prevent Firefox from performing client-side validation when Legacy XHTML mode is set.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I have no idea why the ASP.Net team chose to do this for validation. Perhaps the Legacy XHTML setting should have been called &amp;quot;ASPNetv1Conformance&amp;quot; because that&amp;#39;s actually what it does. The docs for Legacy mode state:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;quot;Reverts a number of rendering changes made for conformance to the v1.1 
rendering behavior.&amp;quot;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class = "shareblock"&gt;&lt;strong&gt;Share this post:&lt;/strong&gt; &lt;a href = "mailto:?body=Thought you might like this: http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx&amp;amp;;subject=Client-side+validation+in+Firefox" target="_blank" title = "Post http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx"&gt;email it!&lt;/a&gt; |  &lt;a href = "http://del.icio.us/post?url=http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx&amp;amp;;title=Client-side+validation+in+Firefox" target="_blank" title = "Post http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx"&gt;bookmark it!&lt;/a&gt; |  &lt;a href = "http://www.digg.com/submit?url=http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx&amp;amp;;phase=2" target="_blank" title = "Post http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx"&gt;digg it!&lt;/a&gt; |  &lt;a href = "http://reddit.com/submit?url=http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx&amp;amp;title=Client-side+validation+in+Firefox" target="_blank" title = "Post http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx"&gt;reddit!&lt;/a&gt; |  &lt;a href = "http://www.dotnetkicks.com/submit/?url=http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx&amp;amp;;title=Client-side+validation+in+Firefox" target="_blank" title = "Post http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx"&gt;kick it!&lt;/a&gt; |  &lt;a href = "https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;;mkt=en-us&amp;amp;;url=http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx&amp;amp;;title=Client-side+validation+in+Firefox&amp;amp;;top=1" target="_blank" title = "Post http://aspadvice.com/blogs/rbirkby/archive/2006/11/01/Client_2D00_side-validation-in-Firefox.aspx"&gt;live it!&lt;/a&gt;&lt;/div&gt;&lt;img src="http://aspadvice.com/aggbug.aspx?PostID=23784" width="1" height="1"&gt;</description><category domain="http://aspadvice.com/blogs/rbirkby/archive/tags/expando/default.aspx">expando</category><category domain="http://aspadvice.com/blogs/rbirkby/archive/tags/validation/default.aspx">validation</category><category domain="http://aspadvice.com/blogs/rbirkby/archive/tags/xhtml/default.aspx">xhtml</category><category domain="http://aspadvice.com/blogs/rbirkby/archive/tags/asp.net/default.aspx">asp.net</category><category domain="http://aspadvice.com/blogs/rbirkby/archive/tags/html/default.aspx">html</category><category domain="http://aspadvice.com/blogs/rbirkby/archive/tags/dotnet/default.aspx">dotnet</category></item></channel></rss>