My guess is that it is an unintentional bug in the framework.  The problem
is that when validators were added to a page initially, they add themselves
to the Page.Validators collection.  When you move them, they disconnect but
there is no obvious way to reconnect them.  As a work around I went through
each control that I moved (and all of their child controls) and added them
to the Validator collection if they are an Ivalidator.  It feels like a
hack, but I am going to contact MS and see if I am missing something
obvious.


Thanks,

Shawn Wildermuth
[EMAIL PROTECTED]
Author of Pragmatic ADO.NET
http://adoguy.com/book
http://ONDotnet.com
Microsoft .NET MVP

> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Shawn Wildermuth
> Sent: Wednesday, February 04, 2004 4:21 PM
> To: [EMAIL PROTECTED]
> Subject: [ADVANCED-DOTNET] Fiddling with Controls collection
> in ASP.NET
>
> Caveat:  I decided to post it to Advanced since what I am
> trying to do is a little ASP.NET black magic.
>
> I have created a base ASP.NET class that derives from
> System.Web.UI.Page.
> This class's job is to create a master page for all Pages in
> a particular application.  In this class I do the following:
>
> - On it's OnInit() call, I gather all the controls for the
>   page's HtmlForm object and remove them from the HtmlForm's
>   Controls collection.
> - I then load a specific UserControl that contains the master
>   page information.
> - Lastly, I add all the controls that used to live in the
>   HtmlForm'ss Control's collection to a control within
>   the Master Page User Control.
>
> All of this worked well until I ran into validators.  Quick
> background on client-side validation.  When a page has
> validators, client scripts are added to the page and
> ultimately called from a submit button on the page.
> After generating a page, a typical button goes from:
>
> <asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
>
> And makes it:
>
> <input type="submit"
>        name="WebUserControl11:Button1"
>        value="Button"
>        onclick="if (typeof(Page_ClientValidate) ==
> 'function') Page_ClientValidate(); "
>        language="javascript"
>        id="WebUserControl11_Button1" />
>
> The magic is the onclick event.  This forces the page to
> validate.  The problem is that with my base page class this
> fixup when it renders the button never happens.  I've delved
> into a myriad of possible solutions and have concluded the
> following information:
>
> - Changing the time when the control fiddling happens
>   seems to have no affect.
> - Embedding a form within another control (using a User
>   Control) does not make this happen.
> - Commenting out the code that does the re-parenting of
>   the controls in my base class resolves the issue (but
>   obviously doesn't really fix it).  Therefore the
>   subclassing of the Page class is not the issue.
>
> What I am looking for is some insight to how the validator
> code fix-ups happen.  I am happy to reverse engineer the
> rendering to see when it happens to find clues as how to get
> around the issue, but I haven't had any success with
> Reflector yet.  Anyone run into this or can give me an idea
> of where to start to look about where the fixup rendering happens?
>
> TIA
>
>
> Thanks,
>
> Shawn Wildermuth
> [EMAIL PROTECTED]
> Author of Pragmatic ADO.NET
> http://adoguy.com/book
> http://ONDotnet.com
> Microsoft .NET MVP
>
> ===================================
> This list is hosted by DevelopMentor.  http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
> http://discuss.develop.com
>

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to