472,798 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,798 software developers and data experts.

PreInit event in usercontrol

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.
Dec 22 '05 #1
9 14315
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" <ma************@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: <#G**************@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!tk2msft ngp13.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.
|
|
|

Dec 23 '05 #2
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: <#G**************@tk2msftngp13.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@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: <zm**************@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" <ma************@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: <#G**************@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!tk2msft ngp13.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.
| |
| |
| |
|
|

Dec 29 '05 #3
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: <#G**************@tk2msftngp13.phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@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: <zm**************@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" <ma************@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: <#G**************@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!tk2msft ngp13.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.
| |
| |
| |
|
|

Jan 1 '06 #4
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?= <ma************@noemail.noemail>
| References: <#G**************@tk2msftngp13.phx.gbl>
<zm**************@TK2MSFTNGXA02.phx.gbl>
<8o*************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: PreInit event in usercontrol
| Date: Sun, 1 Jan 2006 12:11:02 -0800
| Lines: 171
| Message-ID: <2A**********************************@microsoft.co m>
| 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!TK2MSFT NGXA03.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: <#G**************@tk2msftngp13.phx.gbl>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > | From: st*****@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: <zm**************@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" <ma************@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: <#G**************@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!tk2msft ngp13.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.
| > | |
| > | |
| > | |
| > |
| > |
| >
| >
|

Jan 3 '06 #5
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?= <ma************@noemail.noemail>
| References: <#G**************@tk2msftngp13.phx.gbl>
<zm**************@TK2MSFTNGXA02.phx.gbl>
<8o*************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: PreInit event in usercontrol
| Date: Sun, 1 Jan 2006 12:11:02 -0800
| Lines: 171
| Message-ID: <2A**********************************@microsoft.co m>
| 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!TK2MSFT NGXA03.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: <#G**************@tk2msftngp13.phx.gbl>
| > | MIME-Version: 1.0
| > | Content-Type: text/plain
| > | Content-Transfer-Encoding: 7bit
| > | From: st*****@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: <zm**************@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" <ma************@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: <#G**************@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!tk2msft ngp13.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.
| > | |
| > | |
| > | |
| > |
| > |
| >
| >
|

Jan 3 '06 #6
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
| thread-index: AcYQfGJFjaOxVUPER0uVE2KgkpW00A==
| X-WBNR-Posting-Host: 216.213.25.254
| From: =?Utf-8?B?TWFyY2VsbyBDYWJyZXJh?= <ma************@noemail.noemail>
| References: <#G**************@tk2msftngp13.phx.gbl>
<zm**************@TK2MSFTNGXA02.phx.gbl>
<8o*************@TK2MSFTNGXA02.phx.gbl>
<2A**********************************@microsoft.co m>
<XD**************@TK2MSFTNGXA02.phx.gbl>
| Subject: RE: PreInit event in usercontrol
| Date: Tue, 3 Jan 2006 07:43:03 -0800
| Lines: 262
| Message-ID: <0D**********************************@microsoft.co m>
| 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!TK2MSFT NGXA03.phx.gbl
| Xref: TK2MSFTNGXA02.phx.gbl
microsoft.public.dotnet.framework.aspnet:368279
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| 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?=
<ma************@noemail.noemail>
| > | References: <#G**************@tk2msftngp13.phx.gbl>
| > <zm**************@TK2MSFTNGXA02.phx.gbl>
| > <8o*************@TK2MSFTNGXA02.phx.gbl>
| > | Subject: RE: PreInit event in usercontrol
| > | Date: Sun, 1 Jan 2006 12:11:02 -0800
| > | Lines: 171
| > | Message-ID: <2A**********************************@microsoft.co m>
| > | 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!TK2MSFT NGXA03.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: <#G**************@tk2msftngp13.phx.gbl>
| > | > | MIME-Version: 1.0
| > | > | Content-Type: text/plain
| > | > | Content-Transfer-Encoding: 7bit
| > | > | From: st*****@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: <zm**************@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" <ma************@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: <#G**************@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!tk2msft ngp13.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.
| > | > | |
| > | > | |
| > | > | |
| > | > |
| > | > |
| > | >
| > | >
| > |
| >
| >
|

Jan 4 '06 #7
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.


Jan 16 '06 #8
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.


Jan 16 '06 #9
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.
"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.


Jan 19 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: nail | last post by:
Hi. Anyone knows how can I change the theme from my custom control. My custom control render a dropdownlist with the availables themes, getting in the Themes folder. But when I try to chane the...
2
by: shapper | last post by:
Hello, I need to set, at runtime, MyLabel.SkinID="MySkinID". I know this must be done in Page PreInit event. However, MyLabel is in my Master Page. I tried to add the Page PreInit event...
1
by: needin4mation | last post by:
I have this code. The preinit never fires: public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Label1.Text...
6
by: Rahul | last post by:
this is my code in preinit event I have "hlinkAdd" as hyperlink web control and i am using a master page, and below code is of content page preinit event. Protected Sub Page_PreInit(ByVal sender...
0
by: Rahul | last post by:
this is my code in preinit event I have "hlinkAdd" as hyperlink web control and i am using a master page, and below code is of content page preinit event. Protected Sub Page_PreInit(ByVal sender...
5
by: WT | last post by:
Hello, It seems that Page_PreInit is not run automatically when AutoEventWireUp is set for the Page as it is for Page_Load or Page_Init. Somebody could confirm this missing point ? CS
1
by: =?Utf-8?B?TWFubnkgQ2hvaGFu?= | last post by:
I have page with Two User Controls. One of the user control has a Drop Down List with AutoPostback=true. How can i execute a function inside the second user control when the a different value is...
3
by: Morgan Cheng | last post by:
"Server.Transfer(Request.FilePath);" make server re-evaluate current page. In debugger, I found that though the page's OnPreInit is called, delegates attached in HttpModule is not executed. Why...
0
by: shashank narayan | last post by:
what is preinit event in asp.net and why it is used?
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.