<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>The .NET Universe revealed! - techniques for the .NET Developer - MCMS</title>
    <link>http://blogs.mastronardi.be/Sandro/</link>
    <description>The secrets of .NET Development</description>
    <language>en-us</language>
    <copyright>Sandro Mastronardi</copyright>
    <lastBuildDate>Thu, 21 Dec 2006 16:26:55 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>sandro.mastronardi@mastrosoft.com</managingEditor>
    <webMaster>sandro.mastronardi@mastrosoft.com</webMaster>
    <item>
      <trackback:ping>http://blogs.mastronardi.be/Sandro/Trackback.aspx?guid=686c7403-4063-4ad4-864f-7980ca012f55</trackback:ping>
      <pingback:server>http://blogs.mastronardi.be/Sandro/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.mastronardi.be/Sandro/PermaLink,guid,686c7403-4063-4ad4-864f-7980ca012f55.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://blogs.mastronardi.be/Sandro/CommentView,guid,686c7403-4063-4ad4-864f-7980ca012f55.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.mastronardi.be/Sandro/SyndicationService.asmx/GetEntryCommentsRss?guid=686c7403-4063-4ad4-864f-7980ca012f55</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <em>
            <strong>
              <font color="#ffa500">If you don't use MCMS, you can still use a big part
of this Christmas gift, so read on.</font>
            </strong>
          </em>
        </p>
        <p>
          <font color="#000000">Have you ever tried making Xhtml Valid website's with MCMS,
I think not many of you have.</font>
        </p>
        <p>
          <font color="#000000">I ran in to this too, but only after trying a part of the solution
for another reason. That reason was to fix the broken Action in the Html form.<br />
I found some solutions on the internet to fix this issue for Url Rewriting in pure
.Net (1.1) websites.<br /></font>
          <font color="#000000">(This one for example: <a href="http://www.liquid-internet.co.uk/content/dynamic/pages/series1article1.aspx">http://www.liquid-internet.co.uk/content/dynamic/pages/series1article1.aspx</a>)<br />
This article shows how to remove the name attribute and change the action path to
something else, like say... the MCMS 'nice' url.</font>
        </p>
        <p>
          <font color="#000000">Everything seemed to work just fine, untill.... I added the
console on the page which has to be in the form. There is a bug in the console code
that checks if the console is placed inside an HtmlForm. The check does a hard check
like this:</font>
        </p>
        <font color="#000000">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">typeof</span>(System.Web.UI.HtmlControls.HtmlForm)
== formobject.GetType())</span>
          </p>
        </font>
        <p>
          <font color="#000000">Instead of</font>
        </p>
        <font color="#000000">
          <p>
            <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
              <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">if</span>(formobject <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">is</span> System.Web.UI.HtmlControls.HtmlForm)</span>
          </p>
        </font>
        <p>
          <font color="#000000">This makes inheriting the HtmlForm control impossible when using
MCMS. But, luckily, there is a solution called reflection, which is also used on the
code from the other article.<br />
With Reflection it was possible to override the OnInit method and still fill all private
variables and call all private methods. I had already abandoned this Idea in the initial
project beause it was taking too long for the purpose. But around eight months later
there appeared a problem. The dutch government requests that their websites are now
XHTML1.0 Strict. This was not possible since the HtmlForm could not be overridden.
Since we work alot for the government we had to find a solution to that problem....
which I had almost solved when I could write to private variables (couldn't find how
to do that because it uses FieldInfo class where I expected something with 'Variable'
in the name. But eight months later there was something more in google about reflection
and private variables so this time I founc which class to use and I could finish the
job.</font>
        </p>
        <p>
          <font color="#000000">At that point I had full control over what was possible with
the HtmlForm and the Console for MCMS. I've overridden them both and changed them
extensively to make the scripts that are rendered Xhtml valid without breaking the
old functionality.</font>
        </p>
        <p>
          <font color="#000000">Another great feature that came with this endless possibilities
was that I could determine myself where to put the viewstate. Maybe you know, maybe
you don't but when google harvests your webpage it only reads the first few kilobytes
of your website. If your website has a large viewstate (which you should prevent anyway)
then you can choose to place it on the bottom of the form instead of the Top (the
default). You should be careful though, because if your application depends extensively
on viewstate and the page is not completely loaded your application might break because
viewstate is not fully loaded yet.</font>
        </p>
        <p>
          <font color="#000000">To do all this functionality I had to override and re-implement
lots of code from Microsoft. I used the <a href="http://www.aisto.com/roeder/dotnet/">.NET
Reflector</a> to get to the original code. Luckily this is possible because we would
have had a big problem and we would definitely loose the government as a customer.</font>
        </p>
        <p>
          <font color="#000000">I haven't placed many code here because the code sample wil
be self explanatory with the comments.</font>
        </p>
        <p>
          <font color="#000000">All I can say now is, good luck with developing all your other
code Xhtml Valid. Because it can be done!
</font>
        </p>
        <p>
          <font color="#000000">Sandro
</font>
        </p>
        <p>
          <a href="http://blogs.mastronardi.be/Sandro/content/binary/XhtmlValidForm.zip">XhtmlValidForm.zip
(10.11 KB)</a>
        </p>
        <p>
          <font size="1">Edit: I found a link that shows that someone else has stumbled on this
too, but unfortunately there was no solution for him at that time: </font>
          <a href="http://www.webservertalk.com/message535195.html">
            <font size="1">http://www.webservertalk.com/message535195.html</font>
          </a>
        </p>
        <img width="0" height="0" src="http://blogs.mastronardi.be/Sandro/aggbug.ashx?id=686c7403-4063-4ad4-864f-7980ca012f55" />
      </body>
      <title>How To make your websites in MCMS XHtml Strict 1.0 Valid</title>
      <guid isPermaLink="false">http://blogs.mastronardi.be/Sandro/PermaLink,guid,686c7403-4063-4ad4-864f-7980ca012f55.aspx</guid>
      <link>http://blogs.mastronardi.be/Sandro/2006/12/21/HowToMakeYourWebsitesInMCMSXHtmlStrict10Valid.aspx</link>
      <pubDate>Thu, 21 Dec 2006 16:26:55 GMT</pubDate>
      <description>&lt;p&gt;
&lt;em&gt;&lt;strong&gt;&lt;font color=#ffa500&gt;If you don't use MCMS, you can still use a big part
of this Christmas gift, so read on.&lt;/font&gt;&lt;/strong&gt;&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Have you ever tried making Xhtml Valid website's with MCMS, I
think not many of you have.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;I ran in to this too, but only after trying a part of the solution
for another reason. That reason was to fix the broken Action in the Html form.&lt;br&gt;
I found some solutions on the internet to fix this issue for Url Rewriting in pure
.Net (1.1) websites.&lt;br&gt;
&lt;/font&gt;&lt;font color=#000000&gt;(This one for example: &lt;a href="http://www.liquid-internet.co.uk/content/dynamic/pages/series1article1.aspx"&gt;http://www.liquid-internet.co.uk/content/dynamic/pages/series1article1.aspx&lt;/a&gt;)&lt;br&gt;
This article shows how to remove the name attribute and change the action path to
something else, like say... the MCMS 'nice' url.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Everything seemed to work just fine, untill.... I added the console
on the page which has to be in the form. There is a bug in the console code that checks
if the console is placed inside an HtmlForm. The check does a hard check like this:&lt;/font&gt;
&lt;/p&gt;
&lt;font color=#000000&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;typeof&lt;/span&gt;(System.Web.UI.HtmlControls.HtmlForm)
== formobject.GetType())&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font color=#000000&gt;Instead of&lt;/font&gt;
&lt;/p&gt;
&lt;font color=#000000&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;if&lt;/span&gt;(formobject &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;is&lt;/span&gt; System.Web.UI.HtmlControls.HtmlForm)&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt; 
&lt;p&gt;
&lt;font color=#000000&gt;This makes inheriting the HtmlForm control impossible when using
MCMS. But, luckily, there is a solution called reflection, which is also used on the
code from the other article.&lt;br&gt;
With Reflection it was possible to override the OnInit method and still fill all private
variables and call all private methods. I had already abandoned this Idea in the initial
project beause it was taking too long for the purpose. But around eight months later
there appeared a problem. The dutch government requests that their websites are now
XHTML1.0 Strict. This was not possible since the HtmlForm could not be overridden.
Since we work alot for the government we had to find a solution to that problem....
which I had almost solved when I could write to private variables (couldn't find how
to do that because it uses FieldInfo class where I expected something with 'Variable'
in the name. But eight months later there was something more in google about reflection
and private variables so this time I founc which class to use and I could finish the
job.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;At that point I had full control over what was possible with the
HtmlForm and the Console for MCMS. I've overridden them both and changed them extensively
to make the scripts that are rendered Xhtml valid without breaking the old functionality.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Another great feature that came with this endless possibilities
was that I could determine myself where to put the viewstate. Maybe you know, maybe
you don't but when google harvests your webpage it only reads the first few kilobytes
of your website. If your website has a large viewstate (which you should prevent anyway)
then you can choose to place it on the bottom of the form instead of the Top (the
default). You should be careful though, because if your application depends extensively
on viewstate and the page is not completely loaded your application might break because
viewstate is not fully loaded yet.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;To do all this functionality I had to override and re-implement
lots of code from Microsoft. I used the &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;.NET
Reflector&lt;/a&gt; to get to the original code. Luckily this is possible because we would
have had a big problem and we would definitely loose the government as a customer.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;I haven't placed many code here because the code sample wil be
self explanatory with the comments.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;All I can say now is, good luck with developing all your other
code Xhtml Valid. Because it can be done!
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#000000&gt;Sandro
&lt;/p&gt;
&lt;p&gt;
&gt;&lt;a href="http://blogs.mastronardi.be/Sandro/content/binary/XhtmlValidForm.zip"&gt;XhtmlValidForm.zip
(10.11 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size=1&gt;Edit: I found a link that shows that someone else has stumbled on this
too, but unfortunately there was no solution for him at that time: &lt;/font&gt;&lt;a href="http://www.webservertalk.com/message535195.html"&gt;&lt;font size=1&gt;http://www.webservertalk.com/message535195.html&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.mastronardi.be/Sandro/aggbug.ashx?id=686c7403-4063-4ad4-864f-7980ca012f55" /&gt;</description>
      <comments>http://blogs.mastronardi.be/Sandro/CommentView,guid,686c7403-4063-4ad4-864f-7980ca012f55.aspx</comments>
      <category>.net</category>
      <category>MCMS</category>
      <category>Reflection</category>
      <category>W3C</category>
      <category>Xhtml</category>
    </item>
  </channel>
</rss>