473,725 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14453
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.ApplySt yleSheetSkin() method , e.g:

=============== ====
TextBox txt = new TextBox();
txt.ID = "txtUC";
txt.AutoPostBac k = true;
txt.TextChanged += new EventHandler(tx t_TextChanged);

phControls.Cont rols.Add(txt);
txt.ApplyStyleS heetSkin(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.noemai l>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: firewall1.tanai nteractive.com 216.213.25.254
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3666 33
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.publi c.dotnet.framew ork.aspnet
| Message-ID: <zm************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 88
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3667 11
| 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.ApplySt yleSheetSkin() method , e.g:
|
| =============== ====
| TextBox txt = new TextBox();
| txt.ID = "txtUC";
| txt.AutoPostBac k = true;
| txt.TextChanged += new EventHandler(tx t_TextChanged);
|
| phControls.Cont rols.Add(txt);
| txt.ApplyStyleS heetSkin(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.noemai l>
| | 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.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: firewall1.tanai nteractive.com 216.213.25.254
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3666 33
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.publi c.dotnet.framew ork.aspnet
| Message-ID: <zm************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 88
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3667 11
| 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.ApplySt yleSheetSkin() method , e.g:
|
| =============== ====
| TextBox txt = new TextBox();
| txt.ID = "txtUC";
| txt.AutoPostBac k = true;
| txt.TextChanged += new EventHandler(tx t_TextChanged);
|
| phControls.Cont rols.Add(txt);
| txt.ApplyStyleS heetSkin(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.noemai l>
| | 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.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: firewall1.tanai nteractive.com 216.213.25.254
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3666 33
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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: AcYPD30JIUMlpHo 6Sn+47FEA1e5jkw ==
| X-WBNR-Posting-Host: 69.203.154.124
| From: =?Utf-8?B?TWFyY2VsbyB DYWJyZXJh?= <ma************ @noemail.noemai l>
| References: <#G************ **@tk2msftngp13 .phx.gbl>
<zm************ **@TK2MSFTNGXA0 2.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************ *************** *******@microso ft.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3679 60
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.publi c.dotnet.framew ork.aspnet
| > | Message-ID: <zm************ **@TK2MSFTNGXA0 2.phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | Lines: 88
| > | Path: TK2MSFTNGXA02.p hx.gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3667 11
| > | 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.ApplySt yleSheetSkin() method , e.g:
| > |
| > | =============== ====
| > | TextBox txt = new TextBox();
| > | txt.ID = "txtUC";
| > | txt.AutoPostBac k = true;
| > | txt.TextChanged += new EventHandler(tx t_TextChanged);
| > |
| > | phControls.Cont rols.Add(txt);
| > | txt.ApplyStyleS heetSkin(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.noemai l>
| > | | 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.publi c.dotnet.framew ork.aspnet
| > | | NNTP-Posting-Host: firewall1.tanai nteractive.com 216.213.25.254
| > | | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| > | | Xref: TK2MSFTNGXA02.p hx.gbl
| > | microsoft.publi c.dotnet.framew ork.aspnet:3666 33
| > | | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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: AcYPD30JIUMlpHo 6Sn+47FEA1e5jkw ==
| X-WBNR-Posting-Host: 69.203.154.124
| From: =?Utf-8?B?TWFyY2VsbyB DYWJyZXJh?= <ma************ @noemail.noemai l>
| References: <#G************ **@tk2msftngp13 .phx.gbl>
<zm************ **@TK2MSFTNGXA0 2.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************ *************** *******@microso ft.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3679 60
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.publi c.dotnet.framew ork.aspnet
| > | Message-ID: <zm************ **@TK2MSFTNGXA0 2.phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | Lines: 88
| > | Path: TK2MSFTNGXA02.p hx.gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3667 11
| > | 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.ApplySt yleSheetSkin() method , e.g:
| > |
| > | =============== ====
| > | TextBox txt = new TextBox();
| > | txt.ID = "txtUC";
| > | txt.AutoPostBac k = true;
| > | txt.TextChanged += new EventHandler(tx t_TextChanged);
| > |
| > | phControls.Cont rols.Add(txt);
| > | txt.ApplyStyleS heetSkin(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.noemai l>
| > | | 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.publi c.dotnet.framew ork.aspnet
| > | | NNTP-Posting-Host: firewall1.tanai nteractive.com 216.213.25.254
| > | | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| > | | Xref: TK2MSFTNGXA02.p hx.gbl
| > | microsoft.publi c.dotnet.framew ork.aspnet:3666 33
| > | | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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: AcYQfGJFjaOxVUP ER0uVE2KgkpW00A ==
| X-WBNR-Posting-Host: 216.213.25.254
| From: =?Utf-8?B?TWFyY2VsbyB DYWJyZXJh?= <ma************ @noemail.noemai l>
| References: <#G************ **@tk2msftngp13 .phx.gbl>
<zm************ **@TK2MSFTNGXA0 2.phx.gbl>
<8o************ *@TK2MSFTNGXA02 .phx.gbl>
<2A************ *************** *******@microso ft.com>
<XD************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: RE: PreInit event in usercontrol
| Date: Tue, 3 Jan 2006 07:43:03 -0800
| Lines: 262
| Message-ID: <0D************ *************** *******@microso ft.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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3682 79
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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: AcYPD30JIUMlpHo 6Sn+47FEA1e5jkw ==
| > | X-WBNR-Posting-Host: 69.203.154.124
| > | From: =?Utf-8?B?TWFyY2VsbyB DYWJyZXJh?=
<ma************ @noemail.noemai l>
| > | References: <#G************ **@tk2msftngp13 .phx.gbl>
| > <zm************ **@TK2MSFTNGXA0 2.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************ *************** *******@microso ft.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.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| > | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGXA03.phx .gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3679 60
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.publi c.dotnet.framew ork.aspnet
| > | > | Message-ID: <zm************ **@TK2MSFTNGXA0 2.phx.gbl>
| > | > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | > | Lines: 88
| > | > | Path: TK2MSFTNGXA02.p hx.gbl
| > | > | Xref: TK2MSFTNGXA02.p hx.gbl
| > | > microsoft.publi c.dotnet.framew ork.aspnet:3667 11
| > | > | 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.ApplySt yleSheetSkin() method , e.g:
| > | > |
| > | > | =============== ====
| > | > | TextBox txt = new TextBox();
| > | > | txt.ID = "txtUC";
| > | > | txt.AutoPostBac k = true;
| > | > | txt.TextChanged += new EventHandler(tx t_TextChanged);
| > | > |
| > | > | phControls.Cont rols.Add(txt);
| > | > | txt.ApplyStyleS heetSkin(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.noemai l>
| > | > | | 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.publi c.dotnet.framew ork.aspnet
| > | > | | NNTP-Posting-Host: firewall1.tanai nteractive.com 216.213.25.254
| > | > | | Path:
| > TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!tk 2msftngp13.phx. gbl
| > | > | | Xref: TK2MSFTNGXA02.p hx.gbl
| > | > | microsoft.publi c.dotnet.framew ork.aspnet:3666 33
| > | > | | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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="refreshscri pt_panel" visible="False" runat="server"
enableviewstate ="False">
<script language="javas cript" 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
2415
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 Page.Theme property, I get this error: The 'Theme' property can only be set in or before the Page_PreInit event So, how can I set the Theme in or befor the Page_PreInit?
2
7107
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 on my master page but it is not available. Only in normal pages.
1
1657
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 = Profile.FullName; }
6
2863
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 As Object, ByVal e As System.EventArgs) Handles Me.PreInit If Request.QueryString("process") = "" Or Request.QueryString("process") = "Add" Then hlinkAdd.SkinID = "up" (error is thrown here Object reference not set to an instance of an object)...
0
1066
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 As Object, ByVal e As System.EventArgs) Handles Me.PreInit If Request.QueryString("process") = "" Or Request.QueryString("process") = "Add" Then hlinkAdd.SkinID = "up" (error is thrown here Object reference not set to an instance of an...
5
7972
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
1212
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 selected in the first user control? Manny
3
2524
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 ASP.NET is designed in such a way? To make the page executed from scratch, I have to use Resposne.Redirect(Request.FilePath), but this will waste a networking roundtrip.
0
1188
by: shashank narayan | last post by:
what is preinit event in asp.net and why it is used?
0
8888
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9113
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2635
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.