<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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/" version="2.0">
  <channel>
    <title>OOP - There It Is - Dynamic Controls</title>
    <link>http://www.vpsw.com/blogbaby/</link>
    <description>A Very Practical Blog</description>
    <language>en-us</language>
    <copyright>Dean Fiala</copyright>
    <lastBuildDate>Thu, 20 Apr 2006 14:22:51 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>dfiala@vpsw.com</managingEditor>
    <webMaster>dfiala@vpsw.com</webMaster>
    <item>
      <trackback:ping>http://www.vpsw.com/blogbaby/Trackback.aspx?guid=fc35f95e-c9d2-488a-8a90-a20e1b24433a</trackback:ping>
      <pingback:server>http://www.vpsw.com/blogbaby/pingback.aspx</pingback:server>
      <pingback:target>http://www.vpsw.com/blogbaby/PermaLink,guid,fc35f95e-c9d2-488a-8a90-a20e1b24433a.aspx</pingback:target>
      <dc:creator>Dean</dc:creator>
      <wfw:comment>http://www.vpsw.com/blogbaby/CommentView,guid,fc35f95e-c9d2-488a-8a90-a20e1b24433a.aspx</wfw:comment>
      <wfw:commentRss>http://www.vpsw.com/blogbaby/SyndicationService.asmx/GetEntryCommentsRss?guid=fc35f95e-c9d2-488a-8a90-a20e1b24433a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">This is just a quickie.  I'm re-doing
a rather large input form using a DataGrid to let the user navigate it, filter it,
sort it, etc. Looked like an ideal opportunity to try adding AJAX into the mix, to
avoid posting the whole thing back. It thought it was working very nicely, then I
noticed that the rows were getting incorrect contents when I was filtering the grid
-- some of the values were staying in place and being combined with the rows that
"slid up" because of the filtering.  One column in the grid has a dynamically
loaded user control based on the contents of the row. The user control can display
between 1-4 text boxes and contains validation controls as well. This  column
was not displaying correctly when filtering.<br /><br />
I figured the AJAX solution I am using was buggy, so I went to the AJAX package's
user forum and found a post regarding a similar problem.  One respondent stated
that this was not an issue with AJAX, but with the DataGrid and the way it worked
with ViewState to create the controls (GridView in 2.0 is supposedly immune). Sounded
plausible and would be simple enough to test.<br /><br />
One of the nice things about the AJAX package I'm using is that it is fairily non-intrusive,
so I split out all the basic page code into a base class and created two pages that
inherited from it -- one AJAX-enabled and one conventional.  This way I'd be
able isolate AJAX specific problems from DataGrid problems without having to change
the code in two places.  
<br /><br />
I ran the conventional page, applied the filter, waited for it to postback, waited,
waited, and son-of-gun, the same exact issue as the AJAX-enabled grid. Mangled up
user controls.  
<br /><br />
Not desiring to become a DataGrid ViewState expert this morning and delve into how
the control tree was being screwed up, I took a guess that the control IDs forthe
user control might be responsible.  I added some code to explicitly set the ID
property to a unique value for each control when they were created. Voila!  No
more mangled contents.  Everything was rendering as expected on both the conventional
and Ajax-enabled grids. 
<br /><br />
Since I was not setting the IDs for these explicitly, they were all named <b>ctl0</b>. 
Now, the full name inlcuded the gridname and row qualifier as well, <b>dgParameters__ctl3__ctl0</b> for
example, but after applying the filter,  there is no way for the grid to differentiate
between the old row three and the new row three, and hence strange results appear. 
By explicitly setting the ID on the user control to something unique this no longer
happens and I can get back to getting this all working.<br /><br />
More on the AJAX goodies soon.<br /><p></p><img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=fc35f95e-c9d2-488a-8a90-a20e1b24433a" /></body>
      <title>DataGrid And Dynamic Controls</title>
      <guid isPermaLink="false">http://www.vpsw.com/blogbaby/PermaLink,guid,fc35f95e-c9d2-488a-8a90-a20e1b24433a.aspx</guid>
      <link>http://www.vpsw.com/blogbaby/PermaLink,guid,fc35f95e-c9d2-488a-8a90-a20e1b24433a.aspx</link>
      <pubDate>Thu, 20 Apr 2006 14:22:51 GMT</pubDate>
      <description>This is just a quickie.&amp;nbsp; I'm re-doing a rather large input form using a DataGrid to let the user navigate it, filter it, sort it, etc. Looked like an ideal opportunity to try adding AJAX into the mix, to avoid posting the whole thing back. It thought it was working very nicely, then I noticed that the rows were getting incorrect contents when I was filtering the grid -- some of the values were staying in place and being combined with the rows that "slid up" because of the filtering.&amp;nbsp; One column in the grid has a dynamically loaded user control based on the contents of the row. The user control can display between 1-4 text boxes and contains validation controls as well. This&amp;nbsp; column was not displaying correctly when filtering.&lt;br&gt;
&lt;br&gt;
I figured the AJAX solution I am using was buggy, so I went to the AJAX package's
user forum and found a post regarding a similar problem.&amp;nbsp; One respondent stated
that this was not an issue with AJAX, but with the DataGrid and the way it worked
with ViewState to create the controls (GridView in 2.0 is supposedly immune). Sounded
plausible and would be simple enough to test.&lt;br&gt;
&lt;br&gt;
One of the nice things about the AJAX package I'm using is that it is fairily non-intrusive,
so I split out all the basic page code into a base class and created two pages that
inherited from it -- one AJAX-enabled and one conventional.&amp;nbsp; This way I'd be
able isolate AJAX specific problems from DataGrid problems without having to change
the code in two places.&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
I ran the conventional page, applied the filter, waited for it to postback, waited,
waited, and son-of-gun, the same exact issue as the AJAX-enabled grid. Mangled up
user controls.&amp;nbsp; 
&lt;br&gt;
&lt;br&gt;
Not desiring to become a DataGrid ViewState expert this morning and delve into how
the control tree was being screwed up, I took a guess that the control IDs forthe
user control might be responsible.&amp;nbsp; I added some code to explicitly set the ID
property to a unique value for each control when they were created. Voila!&amp;nbsp; No
more mangled contents.&amp;nbsp; Everything was rendering as expected on both the conventional
and Ajax-enabled grids. 
&lt;br&gt;
&lt;br&gt;
Since I was not setting the IDs for these explicitly, they were all named &lt;b&gt;ctl0&lt;/b&gt;.&amp;nbsp;
Now, the full name inlcuded the gridname and row qualifier as well, &lt;b&gt;dgParameters__ctl3__ctl0&lt;/b&gt; for
example, but after applying the filter,&amp;nbsp; there is no way for the grid to differentiate
between the old row three and the new row three, and hence strange results appear.&amp;nbsp;
By explicitly setting the ID on the user control to something unique this no longer
happens and I can get back to getting this all working.&lt;br&gt;
&lt;br&gt;
More on the AJAX goodies soon.&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.vpsw.com/blogbaby/aggbug.ashx?id=fc35f95e-c9d2-488a-8a90-a20e1b24433a" /&gt;</description>
      <comments>http://www.vpsw.com/blogbaby/CommentView,guid,fc35f95e-c9d2-488a-8a90-a20e1b24433a.aspx</comments>
      <category>AJAX</category>
      <category>DataGrid</category>
      <category>Dynamic Controls</category>
    </item>
  </channel>
</rss>