|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
PreInit event in usercontrolI have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is that the webcontrols get created on the OnLoad event of the usercontrol and the event handlers are assigned at the same time. I have to click twice on the controls for the events to be raised, the first time nothing happens, the second time the event handler fires up. Reading the msdn info it says that for pages, the dynamically created webcontrols should be created in the PreInit event of the page, but usercontrols do not have that event, what is the life-cycle for usercontrols. Also the usercontrol is dynamically loaded into the page at the Load event. Thanks, Marcelo Cabrera. Hi Marcelo,
Welcome to ASPNET newsgroup. Regarding on the dynamic creating webcontrols in UserControl or in asp.net 2.0 web page problem, here are some of my understanding and suggestion: 1. For dynamic webcontrols, it's ok to create them in Page's Load or Init event (Init is the prefered one), this is also the recommendation in asp.net 1.1: #HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET http://support.microsoft.com/kb/317794/en-us 2. For asp.net 2.0, the reason why we recommend that put dynamic controls creation code in PreInit event is the ASP.NET 2.0's Theme/Skin service is applying skin to controls before Init event, so we need to add dynamic controls in page's controls structure in PreInit so as to automatically utilize the page's Theme setting.... But if we create them in Init or Load, we can also manually apply page theme for control through Control.ApplyStyleSheetSkin() method , e.g: =================== TextBox txt = new TextBox(); txt.ID = "txtUC"; txt.AutoPostBack = true; txt.TextChanged += new EventHandler(txt_TextChanged); phControls.Controls.Add(txt); txt.ApplyStyleSheetSkin(Page); ==================== For your scenario, I think the event handler problem may caused by how your Usercontrol (the container) is created and added into page's collection. Is the usercontrol always created and added into page in page's Init or Load event ? If possible, would you provide a simplfied page and the usercontrol so that we can have a look into the detailed code logic? Thanks & Merry Christmas! Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | From: "Marcelo Cabrera" <marcelocabrera@noemail.noemail> microsoft.public.dotnet.framework.aspnet:366633| Subject: PreInit event in usercontrol | Date: Thu, 22 Dec 2005 15:06:17 -0500 | Lines: 21 | X-Priority: 3 | X-MSMail-Priority: Normal | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 | X-RFC2646: Format=Flowed; Original | Message-ID: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | Newsgroups: microsoft.public.dotnet.framework.aspnet | NNTP-Posting-Host: firewall1.tanainteractive.com 216.213.25.254 | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | | Hi, | | I have a user control that in turn creates a bunch of webcontrols | dynamically and handles the events these webcontrols raise. It used to work | fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is | that the webcontrols get created on the OnLoad event of the usercontrol and | the event handlers are assigned at the same time. I have to click twice on | the controls for the events to be raised, the first time nothing happens, | the second time the event handler fires up. | | Reading the msdn info it says that for pages, the dynamically created | webcontrols should be created in the PreInit event of the page, but | usercontrols do not have that event, what is the life-cycle for | usercontrols. | | Also the usercontrol is dynamically loaded into the page at the Load event. | | Thanks, | Marcelo Cabrera. | | | Hi Marcelo,
How are you doing on this issue or does my last reply helps you a little? If there're anything else we can help, please feel free to post here. Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- Show quoteHide quote | X-Tomcat-ID: 104339147 microsoft.public.dotnet.framework.aspnet:366711| References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | MIME-Version: 1.0 | Content-Type: text/plain | Content-Transfer-Encoding: 7bit | From: stch***@online.microsoft.com (Steven Cheng[MSFT]) | Organization: Microsoft | Date: Fri, 23 Dec 2005 03:50:37 GMT | Subject: RE: PreInit event in usercontrol | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | Message-ID: <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> | Newsgroups: microsoft.public.dotnet.framework.aspnet | Lines: 88 | Path: TK2MSFTNGXA02.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122 | | Hi Marcelo, | | Welcome to ASPNET newsgroup. | Regarding on the dynamic creating webcontrols in UserControl or in asp.net | 2.0 web page problem, here are some of my understanding and suggestion: | | 1. For dynamic webcontrols, it's ok to create them in Page's Load or Init | event (Init is the prefered one), this is also the recommendation in | asp.net 1.1: | | #HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET | http://support.microsoft.com/kb/317794/en-us | | 2. For asp.net 2.0, the reason why we recommend that put dynamic controls | creation code in PreInit event is the ASP.NET 2.0's Theme/Skin service is | applying skin to controls before Init event, so we need to add dynamic | controls in page's controls structure in PreInit so as to automatically | utilize the page's Theme setting.... But if we create them in Init or | Load, we can also manually apply page theme for control through | Control.ApplyStyleSheetSkin() method , e.g: | | =================== | TextBox txt = new TextBox(); | txt.ID = "txtUC"; | txt.AutoPostBack = true; | txt.TextChanged += new EventHandler(txt_TextChanged); | | phControls.Controls.Add(txt); | txt.ApplyStyleSheetSkin(Page); | ==================== | | | For your scenario, I think the event handler problem may caused by how your | Usercontrol (the container) is created and added into page's collection. Is | the usercontrol always created and added into page in page's Init or Load | event ? | | If possible, would you provide a simplfied page and the usercontrol so that | we can have a look into the detailed code logic? | | Thanks & Merry Christmas! | | Steven Cheng | Microsoft Online Support | | Get Secure! www.microsoft.com/security | (This posting is provided "AS IS", with no warranties, and confers no | rights.) | | | | | | | | | -------------------- | | From: "Marcelo Cabrera" <marcelocabrera@noemail.noemail> | | Subject: PreInit event in usercontrol | | Date: Thu, 22 Dec 2005 15:06:17 -0500 | | Lines: 21 | | X-Priority: 3 | | X-MSMail-Priority: Normal | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 | | X-RFC2646: Format=Flowed; Original | | Message-ID: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | | Newsgroups: microsoft.public.dotnet.framework.aspnet | | NNTP-Posting-Host: firewall1.tanainteractive.com 216.213.25.254 | | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | | Xref: TK2MSFTNGXA02.phx.gbl | microsoft.public.dotnet.framework.aspnet:366633 | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | | | | Hi, | | | | I have a user control that in turn creates a bunch of webcontrols | | dynamically and handles the events these webcontrols raise. It used to | work | | fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is | | that the webcontrols get created on the OnLoad event of the usercontrol | and | | the event handlers are assigned at the same time. I have to click twice | on | | the controls for the events to be raised, the first time nothing happens, | | the second time the event handler fires up. | | | | Reading the msdn info it says that for pages, the dynamically created | | webcontrols should be created in the PreInit event of the page, but | | usercontrols do not have that event, what is the life-cycle for | | usercontrols. | | | | Also the usercontrol is dynamically loaded into the page at the Load | event. | | | | Thanks, | | Marcelo Cabrera. | | | | | | | | Hi Steven,
I was on vacation last week, thanks for the reply. I don't think the problem could be solved without a way to add the handlers for the controls created dynamically. In other words, what's the equivalent of preinit for a usercontrol? The thing is, I have an .ASCX page with a placeholder which in turn gets populated with a few usercontrols in the codebehind, then, those usercontrols have their own events and eventhandlers which in turn may load some other usercontrols during the pageload event of the usercontrols. When that happens the events in the second tier usercontrols don't fire until the second time the user clicks. It all used to work well on 1.1 but with 2.0 something broke, I tried moving the controls creation and event wiring to the pageinit as stated in the documentation (for ascx) but I can't find info about the page life cycle for usercontrols. The usercontrols are always created and added to the page(s) during the load and/or preinit events. Thanks in advance, Marcelo Cabrera. Show quoteHide quote "Steven Cheng[MSFT]" wrote: > Hi Marcelo, > > How are you doing on this issue or does my last reply helps you a little? > If there're anything else we can help, please feel free to post here. > > Regards, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > > -------------------- > | X-Tomcat-ID: 104339147 > | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> > | MIME-Version: 1.0 > | Content-Type: text/plain > | Content-Transfer-Encoding: 7bit > | From: stch***@online.microsoft.com (Steven Cheng[MSFT]) > | Organization: Microsoft > | Date: Fri, 23 Dec 2005 03:50:37 GMT > | Subject: RE: PreInit event in usercontrol > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet > | Message-ID: <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> > | Newsgroups: microsoft.public.dotnet.framework.aspnet > | Lines: 88 > | Path: TK2MSFTNGXA02.phx.gbl > | Xref: TK2MSFTNGXA02.phx.gbl > microsoft.public.dotnet.framework.aspnet:366711 > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122 > | > | Hi Marcelo, > | > | Welcome to ASPNET newsgroup. > | Regarding on the dynamic creating webcontrols in UserControl or in > asp.net > | 2.0 web page problem, here are some of my understanding and suggestion: > | > | 1. For dynamic webcontrols, it's ok to create them in Page's Load or Init > | event (Init is the prefered one), this is also the recommendation in > | asp.net 1.1: > | > | #HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET > | http://support.microsoft.com/kb/317794/en-us > | > | 2. For asp.net 2.0, the reason why we recommend that put dynamic controls > | creation code in PreInit event is the ASP.NET 2.0's Theme/Skin service is > | applying skin to controls before Init event, so we need to add dynamic > | controls in page's controls structure in PreInit so as to automatically > | utilize the page's Theme setting.... But if we create them in Init or > | Load, we can also manually apply page theme for control through > | Control.ApplyStyleSheetSkin() method , e.g: > | > | =================== > | TextBox txt = new TextBox(); > | txt.ID = "txtUC"; > | txt.AutoPostBack = true; > | txt.TextChanged += new EventHandler(txt_TextChanged); > | > | phControls.Controls.Add(txt); > | txt.ApplyStyleSheetSkin(Page); > | ==================== > | > | > | For your scenario, I think the event handler problem may caused by how > your > | Usercontrol (the container) is created and added into page's collection. > Is > | the usercontrol always created and added into page in page's Init or > Load > | event ? > | > | If possible, would you provide a simplfied page and the usercontrol so > that > | we can have a look into the detailed code logic? > | > | Thanks & Merry Christmas! > | > | Steven Cheng > | Microsoft Online Support > | > | Get Secure! www.microsoft.com/security > | (This posting is provided "AS IS", with no warranties, and confers no > | rights.) > | > | > | > | > | > | > | > | > | -------------------- > | | From: "Marcelo Cabrera" <marcelocabrera@noemail.noemail> > | | Subject: PreInit event in usercontrol > | | Date: Thu, 22 Dec 2005 15:06:17 -0500 > | | Lines: 21 > | | X-Priority: 3 > | | X-MSMail-Priority: Normal > | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 > | | X-RFC2646: Format=Flowed; Original > | | Message-ID: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> > | | Newsgroups: microsoft.public.dotnet.framework.aspnet > | | NNTP-Posting-Host: firewall1.tanainteractive.com 216.213.25.254 > | | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl > | | Xref: TK2MSFTNGXA02.phx.gbl > | microsoft.public.dotnet.framework.aspnet:366633 > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet > | | > | | Hi, > | | > | | I have a user control that in turn creates a bunch of webcontrols > | | dynamically and handles the events these webcontrols raise. It used to > | work > | | fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem > is > | | that the webcontrols get created on the OnLoad event of the usercontrol > | and > | | the event handlers are assigned at the same time. I have to click twice > | on > | | the controls for the events to be raised, the first time nothing > happens, > | | the second time the event handler fires up. > | | > | | Reading the msdn info it says that for pages, the dynamically created > | | webcontrols should be created in the PreInit event of the page, but > | | usercontrols do not have that event, what is the life-cycle for > | | usercontrols. > | | > | | Also the usercontrol is dynamically loaded into the page at the Load > | event. > | | > | | Thanks, > | | Marcelo Cabrera. > | | > | | > | | > | > | > > Thanks for your response Marcelo,
So I can currently get that you dynamically load some container userControls in the aspx page. Then, in those container usercontrol's certain postback events, you create and load some other sub usercontrols, and add event handlers for those sub usercontrols? What's the event, your custom defined events or buildin events? Anyway, Usercontrols dosn't have PreInit event (different from Custom Server control...), we have only Init , Load event for usercontrol where we should put the dynamic child controls creation code.... Thanks, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | Thread-Topic: PreInit event in usercontrol <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> | thread-index: AcYPD30JIUMlpHo6Sn+47FEA1e5jkw== | X-WBNR-Posting-Host: 69.203.154.124 | From: =?Utf-8?B?TWFyY2VsbyBDYWJyZXJh?= <marcelocabrera@noemail.noemail> | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> <8oHHjFGDGHA.***@TK2MSFTNGXA02.phx.gbl> Show quoteHide quote | Subject: RE: PreInit event in usercontrol microsoft.public.dotnet.framework.aspnet:367960| Date: Sun, 1 Jan 2006 12:11:02 -0800 | Lines: 171 | Message-ID: <2AD8447C-EC54-41A0-BE42-FD0F6F71F***@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain; | charset="Utf-8" | Content-Transfer-Encoding: 7bit | X-Newsreader: Microsoft CDO for Windows 2000 | Content-Class: urn:content-classes:message | Importance: normal | Priority: normal | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | Newsgroups: microsoft.public.dotnet.framework.aspnet | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl| | Hi Steven, | | I was on vacation last week, thanks for the reply. | I don't think the problem could be solved without a way to add the handlers | for the controls created dynamically. In other words, what's the equivalent | of preinit for a usercontrol? | | The thing is, I have an .ASCX page with a placeholder which in turn gets | populated with a few usercontrols in the codebehind, then, those usercontrols | have their own events and eventhandlers which in turn may load some other | usercontrols during the pageload event of the usercontrols. When that happens | the events in the second tier usercontrols don't fire until the second time | the user clicks. It all used to work well on 1.1 but with 2.0 something | broke, I tried moving the controls creation and event wiring to the pageinit | as stated in the documentation (for ascx) but I can't find info about the | page life cycle for usercontrols. | | The usercontrols are always created and added to the page(s) during the load | and/or preinit events. | | Thanks in advance, | Marcelo Cabrera. | | | "Steven Cheng[MSFT]" wrote: | | > Hi Marcelo, | > | > How are you doing on this issue or does my last reply helps you a little? | > If there're anything else we can help, please feel free to post here. | > | > Regards, | > | > Steven Cheng | > Microsoft Online Support | > | > Get Secure! www.microsoft.com/security | > (This posting is provided "AS IS", with no warranties, and confers no | > rights.) | > | > | > -------------------- | > | X-Tomcat-ID: 104339147 | > | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | > | MIME-Version: 1.0 | > | Content-Type: text/plain | > | Content-Transfer-Encoding: 7bit | > | From: stch***@online.microsoft.com (Steven Cheng[MSFT]) | > | Organization: Microsoft | > | Date: Fri, 23 Dec 2005 03:50:37 GMT | > | Subject: RE: PreInit event in usercontrol | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | > | Message-ID: <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> | > | Newsgroups: microsoft.public.dotnet.framework.aspnet | > | Lines: 88 | > | Path: TK2MSFTNGXA02.phx.gbl | > | Xref: TK2MSFTNGXA02.phx.gbl | > microsoft.public.dotnet.framework.aspnet:366711 | > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122 | > | | > | Hi Marcelo, | > | | > | Welcome to ASPNET newsgroup. | > | Regarding on the dynamic creating webcontrols in UserControl or in | > asp.net | > | 2.0 web page problem, here are some of my understanding and suggestion: | > | | > | 1. For dynamic webcontrols, it's ok to create them in Page's Load or Init | > | event (Init is the prefered one), this is also the recommendation in | > | asp.net 1.1: | > | | > | #HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET | > | http://support.microsoft.com/kb/317794/en-us | > | | > | 2. For asp.net 2.0, the reason why we recommend that put dynamic controls | > | creation code in PreInit event is the ASP.NET 2.0's Theme/Skin service is | > | applying skin to controls before Init event, so we need to add dynamic | > | controls in page's controls structure in PreInit so as to automatically | > | utilize the page's Theme setting.... But if we create them in Init or | > | Load, we can also manually apply page theme for control through | > | Control.ApplyStyleSheetSkin() method , e.g: | > | | > | =================== | > | TextBox txt = new TextBox(); | > | txt.ID = "txtUC"; | > | txt.AutoPostBack = true; | > | txt.TextChanged += new EventHandler(txt_TextChanged); | > | | > | phControls.Controls.Add(txt); | > | txt.ApplyStyleSheetSkin(Page); | > | ==================== | > | | > | | > | For your scenario, I think the event handler problem may caused by how | > your | > | Usercontrol (the container) is created and added into page's collection. | > Is | > | the usercontrol always created and added into page in page's Init or | > Load | > | event ? | > | | > | If possible, would you provide a simplfied page and the usercontrol so | > that | > | we can have a look into the detailed code logic? | > | | > | Thanks & Merry Christmas! | > | | > | Steven Cheng | > | Microsoft Online Support | > | | > | Get Secure! www.microsoft.com/security | > | (This posting is provided "AS IS", with no warranties, and confers no | > | rights.) | > | | > | | > | | > | | > | | > | | > | | > | | > | -------------------- | > | | From: "Marcelo Cabrera" <marcelocabrera@noemail.noemail> | > | | Subject: PreInit event in usercontrol | > | | Date: Thu, 22 Dec 2005 15:06:17 -0500 | > | | Lines: 21 | > | | X-Priority: 3 | > | | X-MSMail-Priority: Normal | > | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 | > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 | > | | X-RFC2646: Format=Flowed; Original | > | | Message-ID: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | > | | Newsgroups: microsoft.public.dotnet.framework.aspnet | > | | NNTP-Posting-Host: firewall1.tanainteractive.com 216.213.25.254 | > | | Path: Show quoteHide quote | > | | Xref: TK2MSFTNGXA02.phx.gbl | > | microsoft.public.dotnet.framework.aspnet:366633 | > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | > | | | > | | Hi, | > | | | > | | I have a user control that in turn creates a bunch of webcontrols | > | | dynamically and handles the events these webcontrols raise. It used to | > | work | > | | fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem | > is | > | | that the webcontrols get created on the OnLoad event of the usercontrol | > | and | > | | the event handlers are assigned at the same time. I have to click twice | > | on | > | | the controls for the events to be raised, the first time nothing | > happens, | > | | the second time the event handler fires up. | > | | | > | | Reading the msdn info it says that for pages, the dynamically created | > | | webcontrols should be created in the PreInit event of the page, but | > | | usercontrols do not have that event, what is the life-cycle for | > | | usercontrols. | > | | | > | | Also the usercontrol is dynamically loaded into the page at the Load | > | event. | > | | | > | | Thanks, | > | | Marcelo Cabrera. | > | | | > | | | > | | | > | | > | | > | > | Steven,
Yes, you got it right. the events are builtin events, when I need to bubble-up events to the parent usercontrol (for example to remove the child control) that works fine, simple built-in events like button onclick are the events that need to be triggered twice before getting processed. Thanks, Marcelo Cabrera. Show quoteHide quote "Steven Cheng[MSFT]" wrote: > Thanks for your response Marcelo, > > So I can currently get that you dynamically load some container > userControls in the aspx page. Then, in those container usercontrol's > certain postback events, you create and load some other sub usercontrols, > and add event handlers for those sub usercontrols? What's the event, your > custom defined events or buildin events? > > Anyway, Usercontrols dosn't have PreInit event (different from Custom > Server control...), we have only Init , Load event for usercontrol where we > should put the dynamic child controls creation code.... > > Thanks, > > Steven Cheng > Microsoft Online Support > > Get Secure! www.microsoft.com/security > (This posting is provided "AS IS", with no warranties, and confers no > rights.) > > > -------------------- > | Thread-Topic: PreInit event in usercontrol > | thread-index: AcYPD30JIUMlpHo6Sn+47FEA1e5jkw== > | X-WBNR-Posting-Host: 69.203.154.124 > | From: =?Utf-8?B?TWFyY2VsbyBDYWJyZXJh?= <marcelocabrera@noemail.noemail> > | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> > <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> > <8oHHjFGDGHA.***@TK2MSFTNGXA02.phx.gbl> > | Subject: RE: PreInit event in usercontrol > | Date: Sun, 1 Jan 2006 12:11:02 -0800 > | Lines: 171 > | Message-ID: <2AD8447C-EC54-41A0-BE42-FD0F6F71F***@microsoft.com> > | MIME-Version: 1.0 > | Content-Type: text/plain; > | charset="Utf-8" > | Content-Transfer-Encoding: 7bit > | X-Newsreader: Microsoft CDO for Windows 2000 > | Content-Class: urn:content-classes:message > | Importance: normal > | Priority: normal > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 > | Newsgroups: microsoft.public.dotnet.framework.aspnet > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl > | Xref: TK2MSFTNGXA02.phx.gbl > microsoft.public.dotnet.framework.aspnet:367960 > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet > | > | Hi Steven, > | > | I was on vacation last week, thanks for the reply. > | I don't think the problem could be solved without a way to add the > handlers > | for the controls created dynamically. In other words, what's the > equivalent > | of preinit for a usercontrol? > | > | The thing is, I have an .ASCX page with a placeholder which in turn gets > | populated with a few usercontrols in the codebehind, then, those > usercontrols > | have their own events and eventhandlers which in turn may load some other > | usercontrols during the pageload event of the usercontrols. When that > happens > | the events in the second tier usercontrols don't fire until the second > time > | the user clicks. It all used to work well on 1.1 but with 2.0 something > | broke, I tried moving the controls creation and event wiring to the > pageinit > | as stated in the documentation (for ascx) but I can't find info about the > | page life cycle for usercontrols. > | > | The usercontrols are always created and added to the page(s) during the > load > | and/or preinit events. > | > | Thanks in advance, > | Marcelo Cabrera. > | > | > | "Steven Cheng[MSFT]" wrote: > | > | > Hi Marcelo, > | > > | > How are you doing on this issue or does my last reply helps you a > little? > | > If there're anything else we can help, please feel free to post here. > | > > | > Regards, > | > > | > Steven Cheng > | > Microsoft Online Support > | > > | > Get Secure! www.microsoft.com/security > | > (This posting is provided "AS IS", with no warranties, and confers no > | > rights.) > | > > | > > | > -------------------- > | > | X-Tomcat-ID: 104339147 > | > | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> > | > | MIME-Version: 1.0 > | > | Content-Type: text/plain > | > | Content-Transfer-Encoding: 7bit > | > | From: stch***@online.microsoft.com (Steven Cheng[MSFT]) > | > | Organization: Microsoft > | > | Date: Fri, 23 Dec 2005 03:50:37 GMT > | > | Subject: RE: PreInit event in usercontrol > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet > | > | Message-ID: <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet > | > | Lines: 88 > | > | Path: TK2MSFTNGXA02.phx.gbl > | > | Xref: TK2MSFTNGXA02.phx.gbl > | > microsoft.public.dotnet.framework.aspnet:366711 > | > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122 > | > | > | > | Hi Marcelo, > | > | > | > | Welcome to ASPNET newsgroup. > | > | Regarding on the dynamic creating webcontrols in UserControl or in > | > asp.net > | > | 2.0 web page problem, here are some of my understanding and > suggestion: > | > | > | > | 1. For dynamic webcontrols, it's ok to create them in Page's Load or > Init > | > | event (Init is the prefered one), this is also the recommendation in > | > | asp.net 1.1: > | > | > | > | #HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# > .NET > | > | http://support.microsoft.com/kb/317794/en-us > | > | > | > | 2. For asp.net 2.0, the reason why we recommend that put dynamic > controls > | > | creation code in PreInit event is the ASP.NET 2.0's Theme/Skin > service is > | > | applying skin to controls before Init event, so we need to add > dynamic > | > | controls in page's controls structure in PreInit so as to > automatically > | > | utilize the page's Theme setting.... But if we create them in Init > or > | > | Load, we can also manually apply page theme for control through > | > | Control.ApplyStyleSheetSkin() method , e.g: > | > | > | > | =================== > | > | TextBox txt = new TextBox(); > | > | txt.ID = "txtUC"; > | > | txt.AutoPostBack = true; > | > | txt.TextChanged += new EventHandler(txt_TextChanged); > | > | > | > | phControls.Controls.Add(txt); > | > | txt.ApplyStyleSheetSkin(Page); > | > | ==================== > | > | > | > | > | > | For your scenario, I think the event handler problem may caused by > how > | > your > | > | Usercontrol (the container) is created and added into page's > collection. > | > Is > | > | the usercontrol always created and added into page in page's Init or > | > Load > | > | event ? > | > | > | > | If possible, would you provide a simplfied page and the usercontrol > so > | > that > | > | we can have a look into the detailed code logic? > | > | > | > | Thanks & Merry Christmas! > | > | > | > | Steven Cheng > | > | Microsoft Online Support > | > | > | > | Get Secure! www.microsoft.com/security > | > | (This posting is provided "AS IS", with no warranties, and confers no > | > | rights.) > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | > | -------------------- > | > | | From: "Marcelo Cabrera" <marcelocabrera@noemail.noemail> > | > | | Subject: PreInit event in usercontrol > | > | | Date: Thu, 22 Dec 2005 15:06:17 -0500 > | > | | Lines: 21 > | > | | X-Priority: 3 > | > | | X-MSMail-Priority: Normal > | > | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 > | > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 > | > | | X-RFC2646: Format=Flowed; Original > | > | | Message-ID: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> > | > | | Newsgroups: microsoft.public.dotnet.framework.aspnet > | > | | NNTP-Posting-Host: firewall1.tanainteractive.com 216.213.25.254 > | > | | Path: > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl > | > | | Xref: TK2MSFTNGXA02.phx.gbl > | > | microsoft.public.dotnet.framework.aspnet:366633 > | > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet > | > | | > | > | | Hi, > | > | | > | > | | I have a user control that in turn creates a bunch of webcontrols > | > | | dynamically and handles the events these webcontrols raise. It used > to > | > | work > | > | | fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The > problem > | > is > | > | | that the webcontrols get created on the OnLoad event of the > usercontrol > | > | and > | > | | the event handlers are assigned at the same time. I have to click > twice > | > | on > | > | | the controls for the events to be raised, the first time nothing > | > happens, > | > | | the second time the event handler fires up. > | > | | > | > | | Reading the msdn info it says that for pages, the dynamically > created > | > | | webcontrols should be created in the PreInit event of the page, but > | > | | usercontrols do not have that event, what is the life-cycle for > | > | | usercontrols. > | > | | > | > | | Also the usercontrol is dynamically loaded into the page at the > Load > | > | event. > | > | | > | > | | Thanks, > | > | | Marcelo Cabrera. > | > | | > | > | | > | > | | > | > | > | > | > | > > | > > | > > Thanks Marcelo,
Would you provide me a simplified page and usercontrol with some buildin controls(button or textboxes) that are dynamicall loaded and bind event handlers so that I can perform some test on them? Regards, Steven Cheng Microsoft Online Support Get Secure! www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no rights.) -------------------- | Thread-Topic: PreInit event in usercontrol <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> | thread-index: AcYQfGJFjaOxVUPER0uVE2KgkpW00A== | X-WBNR-Posting-Host: 216.213.25.254 | From: =?Utf-8?B?TWFyY2VsbyBDYWJyZXJh?= <marcelocabrera@noemail.noemail> | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> <8oHHjFGDGHA.***@TK2MSFTNGXA02.phx.gbl> <2AD8447C-EC54-41A0-BE42-FD0F6F71F***@microsoft.com> <XD4aiCFEGHA.1***@TK2MSFTNGXA02.phx.gbl> Show quoteHide quote | Subject: RE: PreInit event in usercontrol microsoft.public.dotnet.framework.aspnet:368279| Date: Tue, 3 Jan 2006 07:43:03 -0800 | Lines: 262 | Message-ID: <0D2BB0F5-2BEB-44B2-9426-93ECD79ED***@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain; | charset="Utf-8" | Content-Transfer-Encoding: 7bit | X-Newsreader: Microsoft CDO for Windows 2000 | Content-Class: urn:content-classes:message | Importance: normal | Priority: normal | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | Newsgroups: microsoft.public.dotnet.framework.aspnet | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl Show quoteHide quote | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet <marcelocabrera@noemail.noemail>| | Steven, | | Yes, you got it right. the events are builtin events, when I need to | bubble-up events to the parent usercontrol (for example to remove the child | control) that works fine, simple built-in events like button onclick are the | events that need to be triggered twice before getting processed. | | Thanks, | Marcelo Cabrera. | | "Steven Cheng[MSFT]" wrote: | | > Thanks for your response Marcelo, | > | > So I can currently get that you dynamically load some container | > userControls in the aspx page. Then, in those container usercontrol's | > certain postback events, you create and load some other sub usercontrols, | > and add event handlers for those sub usercontrols? What's the event, your | > custom defined events or buildin events? | > | > Anyway, Usercontrols dosn't have PreInit event (different from Custom | > Server control...), we have only Init , Load event for usercontrol where we | > should put the dynamic child controls creation code.... | > | > Thanks, | > | > Steven Cheng | > Microsoft Online Support | > | > Get Secure! www.microsoft.com/security | > (This posting is provided "AS IS", with no warranties, and confers no | > rights.) | > | > | > -------------------- | > | Thread-Topic: PreInit event in usercontrol | > | thread-index: AcYPD30JIUMlpHo6Sn+47FEA1e5jkw== | > | X-WBNR-Posting-Host: 69.203.154.124 | > | From: =?Utf-8?B?TWFyY2VsbyBDYWJyZXJh?= Show quoteHide quote | > | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | > <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> | > <8oHHjFGDGHA.***@TK2MSFTNGXA02.phx.gbl> | > | Subject: RE: PreInit event in usercontrol | > | Date: Sun, 1 Jan 2006 12:11:02 -0800 | > | Lines: 171 | > | Message-ID: <2AD8447C-EC54-41A0-BE42-FD0F6F71F***@microsoft.com> | > | MIME-Version: 1.0 | > | Content-Type: text/plain; | > | charset="Utf-8" | > | Content-Transfer-Encoding: 7bit | > | X-Newsreader: Microsoft CDO for Windows 2000 | > | Content-Class: urn:content-classes:message | > | Importance: normal | > | Priority: normal | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0 | > | Newsgroups: microsoft.public.dotnet.framework.aspnet | > | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250 | > | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGXA03.phx.gbl | > | Xref: TK2MSFTNGXA02.phx.gbl | > microsoft.public.dotnet.framework.aspnet:367960 | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | > | | > | Hi Steven, | > | | > | I was on vacation last week, thanks for the reply. | > | I don't think the problem could be solved without a way to add the | > handlers | > | for the controls created dynamically. In other words, what's the | > equivalent | > | of preinit for a usercontrol? | > | | > | The thing is, I have an .ASCX page with a placeholder which in turn gets | > | populated with a few usercontrols in the codebehind, then, those | > usercontrols | > | have their own events and eventhandlers which in turn may load some other | > | usercontrols during the pageload event of the usercontrols. When that | > happens | > | the events in the second tier usercontrols don't fire until the second | > time | > | the user clicks. It all used to work well on 1.1 but with 2.0 something | > | broke, I tried moving the controls creation and event wiring to the | > pageinit | > | as stated in the documentation (for ascx) but I can't find info about the | > | page life cycle for usercontrols. | > | | > | The usercontrols are always created and added to the page(s) during the | > load | > | and/or preinit events. | > | | > | Thanks in advance, | > | Marcelo Cabrera. | > | | > | | > | "Steven Cheng[MSFT]" wrote: | > | | > | > Hi Marcelo, | > | > | > | > How are you doing on this issue or does my last reply helps you a | > little? | > | > If there're anything else we can help, please feel free to post here. | > | > | > | > Regards, | > | > | > | > Steven Cheng | > | > Microsoft Online Support | > | > | > | > Get Secure! www.microsoft.com/security | > | > (This posting is provided "AS IS", with no warranties, and confers no | > | > rights.) | > | > | > | > | > | > -------------------- | > | > | X-Tomcat-ID: 104339147 | > | > | References: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | > | > | MIME-Version: 1.0 | > | > | Content-Type: text/plain | > | > | Content-Transfer-Encoding: 7bit | > | > | From: stch***@online.microsoft.com (Steven Cheng[MSFT]) | > | > | Organization: Microsoft | > | > | Date: Fri, 23 Dec 2005 03:50:37 GMT | > | > | Subject: RE: PreInit event in usercontrol | > | > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | > | > | Message-ID: <zmKTXQ3BGHA.1***@TK2MSFTNGXA02.phx.gbl> | > | > | Newsgroups: microsoft.public.dotnet.framework.aspnet | > | > | Lines: 88 | > | > | Path: TK2MSFTNGXA02.phx.gbl | > | > | Xref: TK2MSFTNGXA02.phx.gbl | > | > microsoft.public.dotnet.framework.aspnet:366711 | > | > | NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122 | > | > | | > | > | Hi Marcelo, | > | > | | > | > | Welcome to ASPNET newsgroup. | > | > | Regarding on the dynamic creating webcontrols in UserControl or in | > | > asp.net | > | > | 2.0 web page problem, here are some of my understanding and | > suggestion: | > | > | | > | > | 1. For dynamic webcontrols, it's ok to create them in Page's Load or | > Init | > | > | event (Init is the prefered one), this is also the recommendation in | > | > | asp.net 1.1: | > | > | | > | > | #HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# | > .NET | > | > | http://support.microsoft.com/kb/317794/en-us | > | > | | > | > | 2. For asp.net 2.0, the reason why we recommend that put dynamic | > controls | > | > | creation code in PreInit event is the ASP.NET 2.0's Theme/Skin | > service is | > | > | applying skin to controls before Init event, so we need to add | > dynamic | > | > | controls in page's controls structure in PreInit so as to | > automatically | > | > | utilize the page's Theme setting.... But if we create them in Init | > or | > | > | Load, we can also manually apply page theme for control through | > | > | Control.ApplyStyleSheetSkin() method , e.g: | > | > | | > | > | =================== | > | > | TextBox txt = new TextBox(); | > | > | txt.ID = "txtUC"; | > | > | txt.AutoPostBack = true; | > | > | txt.TextChanged += new EventHandler(txt_TextChanged); | > | > | | > | > | phControls.Controls.Add(txt); | > | > | txt.ApplyStyleSheetSkin(Page); | > | > | ==================== | > | > | | > | > | | > | > | For your scenario, I think the event handler problem may caused by | > how | > | > your | > | > | Usercontrol (the container) is created and added into page's | > collection. | > | > Is | > | > | the usercontrol always created and added into page in page's Init or | > | > Load | > | > | event ? | > | > | | > | > | If possible, would you provide a simplfied page and the usercontrol | > so | > | > that | > | > | we can have a look into the detailed code logic? | > | > | | > | > | Thanks & Merry Christmas! | > | > | | > | > | Steven Cheng | > | > | Microsoft Online Support | > | > | | > | > | Get Secure! www.microsoft.com/security | > | > | (This posting is provided "AS IS", with no warranties, and confers no | > | > | rights.) | > | > | | > | > | | > | > | | > | > | | > | > | | > | > | | > | > | | > | > | | > | > | -------------------- | > | > | | From: "Marcelo Cabrera" <marcelocabrera@noemail.noemail> | > | > | | Subject: PreInit event in usercontrol | > | > | | Date: Thu, 22 Dec 2005 15:06:17 -0500 | > | > | | Lines: 21 | > | > | | X-Priority: 3 | > | > | | X-MSMail-Priority: Normal | > | > | | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 | > | > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 | > | > | | X-RFC2646: Format=Flowed; Original | > | > | | Message-ID: <#GPhcLzBGHA.2***@tk2msftngp13.phx.gbl> | > | > | | Newsgroups: microsoft.public.dotnet.framework.aspnet | > | > | | NNTP-Posting-Host: firewall1.tanainteractive.com 216.213.25.254 | > | > | | Path: | > TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl | > | > | | Xref: TK2MSFTNGXA02.phx.gbl | > | > | microsoft.public.dotnet.framework.aspnet:366633 | > | > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet | > | > | | | > | > | | Hi, | > | > | | | > | > | | I have a user control that in turn creates a bunch of webcontrols | > | > | | dynamically and handles the events these webcontrols raise. It used | > to | > | > | work | > | > | | fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The | > problem | > | > is | > | > | | that the webcontrols get created on the OnLoad event of the | > usercontrol | > | > | and | > | > | | the event handlers are assigned at the same time. I have to click | > twice | > | > | on | > | > | | the controls for the events to be raised, the first time nothing | > | > happens, | > | > | | the second time the event handler fires up. | > | > | | | > | > | | Reading the msdn info it says that for pages, the dynamically | > created | > | > | | webcontrols should be created in the PreInit event of the page, but | > | > | | usercontrols do not have that event, what is the life-cycle for | > | > | | usercontrols. | > | > | | | > | > | | Also the usercontrol is dynamically loaded into the page at the | > Load | > | > | event. | > | > | | | > | > | | Thanks, | > | > | | Marcelo Cabrera. | > | > | | | > | > | | | > | > | | | > | > | | > | > | | > | > | > | > | > | | > | > | Hi!
I have the same problem with UserControls. I have to click twice on the buttons on the control to make them react correctly. It seams to be the "doPostBack" that, by some reason, isn't correct. The scenario is as follows. The page load and 4 user controls are created all with buttons "edit" and "delete" the "doPostBack" for the first control has '_ctl1$...' the next has '_ctl2$...' etc (notice the numbers 1, 2.. etc). When I click the edit button on the first control the second control reacts. by displaying the "edit" box. But now, when I look at the "doPostBack" for the buttons the first control has '_ctl0$...' the second has '_ctl1$...' etc (the numbers start from 0) and now the buttons work for correct control. This implies that there is a problem with associating the correct control Id with the controls the first time they load. Why it is so I'm not able to find out. Dose anyone have an idea how to solve this (have you Marcelo solved your problem) ??? Thanks... Björn Erlendsson Marcelo Cabrera skrev: Show quoteHide quote > Hi, > > I have a user control that in turn creates a bunch of webcontrols > dynamically and handles the events these webcontrols raise. It used to work > fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is > that the webcontrols get created on the OnLoad event of the usercontrol and > the event handlers are assigned at the same time. I have to click twice on > the controls for the events to be raised, the first time nothing happens, > the second time the event handler fires up. > > Reading the msdn info it says that for pages, the dynamically created > webcontrols should be created in the PreInit event of the page, but > usercontrols do not have that event, what is the life-cycle for > usercontrols. > > Also the usercontrol is dynamically loaded into the page at the Load event. > > Thanks, > Marcelo Cabrera. I "fixed" it by loading some javascript after processing the event. The
javascript code will produce another 'postback' wihtout defining the control who did it, then when the user click on a control is like if it was clicked twice. <asp:panel id="refreshscript_panel" visible="False" runat="server" enableviewstate="False"> <script language="javascript" type="text/javascript"> //__doPostBack('',''); document.forms[0].submit(); </script> </asp:panel> just show the panel after the code handling events in your control and you will be ok, but beware that this will produce two postbacks. Show quoteHide quote "bjossi" wrote: > Hi! > > I have the same problem with UserControls. I have to click twice on the > buttons on the control to make them react correctly. It seams to be the > "doPostBack" that, by some reason, isn't correct. The scenario is > as follows. The page load and 4 user controls are created all with > buttons "edit" and "delete" the "doPostBack" for the first > control has '_ctl1$...' the next has '_ctl2$...' etc (notice > the numbers 1, 2.. etc). When I click the edit button on the first > control the second control reacts. by displaying the "edit" box. > But now, when I look at the "doPostBack" for the buttons the first > control has '_ctl0$...' the second has '_ctl1$...' etc (the > numbers start from 0) and now the buttons work for correct control. > This implies that there is a problem with associating the correct > control Id with the controls the first time they load. Why it is so > I'm not able to find out. > > Dose anyone have an idea how to solve this (have you Marcelo solved > your problem) ??? > > Thanks... > Björn Erlendsson > > > > Marcelo Cabrera skrev: > > > Hi, > > > > I have a user control that in turn creates a bunch of webcontrols > > dynamically and handles the events these webcontrols raise. It used to work > > fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is > > that the webcontrols get created on the OnLoad event of the usercontrol and > > the event handlers are assigned at the same time. I have to click twice on > > the controls for the events to be raised, the first time nothing happens, > > the second time the event handler fires up. > > > > Reading the msdn info it says that for pages, the dynamically created > > webcontrols should be created in the PreInit event of the page, but > > usercontrols do not have that event, what is the life-cycle for > > usercontrols. > > > > Also the usercontrol is dynamically loaded into the page at the Load event. > > > > Thanks, > > Marcelo Cabrera. > > Hi!
I have the same problem with UserControls. I have to click twice on the buttons on the control to make them react correctly. It seams to be the "doPostBack" that, by some reason, isn't correct. The scenario is as follows. The page load and 4 user controls are created all with buttons "edit" and "delete" the "doPostBack" for the first control has '_ctl1$...' the next has '_ctl2$...' etc (notice the numbers 1, 2.. etc). When I click the edit button on the first control the second control reacts. by displaying the "edit" box. But now, when I look at the "doPostBack" for the buttons the first control has '_ctl0$...' the second has '_ctl1$...' etc (the numbers start from 0) and now the buttons work for correct control. This implies that there is a problem with associating the correct control Id with the controls the first time they load. Why it is so I'm not able to find out. Dose anyone have an idea how to solve this (have you Marcelo solved your problem) ??? Thanks... Björn Erlendsson Marcelo Cabrera skrev: Show quoteHide quote > Hi, > > I have a user control that in turn creates a bunch of webcontrols > dynamically and handles the events these webcontrols raise. It used to work > fine on ASP .Net 1.1 but when compiled on 2.0 it does not. The problem is > that the webcontrols get created on the OnLoad event of the usercontrol and > the event handlers are assigned at the same time. I have to click twice on > the controls for the events to be raised, the first time nothing happens, > the second time the event handler fires up. > > Reading the msdn info it says that for pages, the dynamically created > webcontrols should be created in the PreInit event of the page, but > usercontrols do not have that event, what is the life-cycle for > usercontrols. > > Also the usercontrol is dynamically loaded into the page at the Load event. > > Thanks, > Marcelo Cabrera.
Other interesting topics
Select string building in C# and ASP.NET
Loading UserControl using New Contructor ..HtmlControls.HtmlInputFile.Saveas(filename) not overwriting Application_Error does not fire Storing an array to a Session need help to convert to VB Virtual Directory How do I run a server side method from javascript?! Path conversion self-signed certificate for Windows XP |
|||||||||||||||||||||||