473,734 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamically loaded control event only reached on 2nd postback

kw
My aspx dynamically loads an ascx into a placeholder. The ascx has an
event. When I click on the submit linkbutton in the ascx, the event does
not fire. But if I click it a second time, it fires.

I put in tracing, and the OnInit (which loads the event handler) is executed
on the initial load and also on the 2nd. It just makes no sense to me. Any
ideas?

Thanks a zillion!!

Dan
Nov 18 '05 #1
5 3483
Dan,

The solution for this one isn't obvious.

Make certain that you're specifying your control's ID. That means do this
inside of the control's page load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

Me.ID = "MyControl1 "

End Sub
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:eU******** *****@TK2MSFTNG P12.phx.gbl...
My aspx dynamically loads an ascx into a placeholder. The ascx has an
event. When I click on the submit linkbutton in the ascx, the event does
not fire. But if I click it a second time, it fires.

I put in tracing, and the OnInit (which loads the event handler) is executed on the initial load and also on the 2nd. It just makes no sense to me. Any ideas?

Thanks a zillion!!

Dan

Nov 18 '05 #2
kw
AMAZING!!! You were right! I'm still not quite sure why this should be
as it is obvious from my situation that something is very wrong about this.
See, the same ascx is being loaded by a treeview to display various objects
represented by different ID's.

On the face of it, it looks like polymorphism is out the window and now I
have to manually create copies of the ascx under different names so I can
assign them the appropriate ID in the instantiation.. ..unless there is a way
to communicate that to the ascx via the viewstate, querystring or some other
means.

What do you suggest?

To make this concrete, here is where things are now:
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID="MyCont rol1";

But it looks like this is what it should be:
//ASPX
private void TreeViewControl _SelectedIndexC hange(object sender,
System.EventArg s e){
TreeNode n = TreeViewControl .GetNodeFromInd ex(e.NewNode);
ViewState["ContentId"]=n.ID; //or some other node dependent variation
Content.Control s.Add(LoadContr ol(n.ID+".ascx" ));
....
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID=ViewSta te["ContentId"];

That looks about right, right? The idea being that ID has to be assigned in
the ASCX Page_Load and that ViewState is the best means of communication.

"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
Dan,

The solution for this one isn't obvious.

Make certain that you're specifying your control's ID. That means do this
inside of the control's page load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

Me.ID = "MyControl1 "

End Sub
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:eU******** *****@TK2MSFTNG P12.phx.gbl...
My aspx dynamically loads an ascx into a placeholder. The ascx has an
event. When I click on the submit linkbutton in the ascx, the event does not fire. But if I click it a second time, it fires.

I put in tracing, and the OnInit (which loads the event handler) is

executed
on the initial load and also on the 2nd. It just makes no sense to me.

Any
ideas?

Thanks a zillion!!

Dan


Nov 18 '05 #3
Dan,

That sounds right. Unfortunately, I can't confirm. You'll just have to try a
few combinations if the way you've described doesn't work. I'm not even
positive that the ID need be defined in the page load routine. I think you
could also define it in the Page Init.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:uu******** ******@TK2MSFTN GP12.phx.gbl...
AMAZING!!! You were right! I'm still not quite sure why this should be as it is obvious from my situation that something is very wrong about this. See, the same ascx is being loaded by a treeview to display various objects represented by different ID's.

On the face of it, it looks like polymorphism is out the window and now I
have to manually create copies of the ascx under different names so I can
assign them the appropriate ID in the instantiation.. ..unless there is a way to communicate that to the ascx via the viewstate, querystring or some other means.

What do you suggest?

To make this concrete, here is where things are now:
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID="MyCont rol1";

But it looks like this is what it should be:
//ASPX
private void TreeViewControl _SelectedIndexC hange(object sender,
System.EventArg s e){
TreeNode n = TreeViewControl .GetNodeFromInd ex(e.NewNode);
ViewState["ContentId"]=n.ID; //or some other node dependent variation
Content.Control s.Add(LoadContr ol(n.ID+".ascx" ));
...
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID=ViewSta te["ContentId"];

That looks about right, right? The idea being that ID has to be assigned in the ASCX Page_Load and that ViewState is the best means of communication.

"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
Dan,

The solution for this one isn't obvious.

Make certain that you're specifying your control's ID. That means do this
inside of the control's page load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

Me.ID = "MyControl1 "

End Sub
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:eU******** *****@TK2MSFTNG P12.phx.gbl...
My aspx dynamically loads an ascx into a placeholder. The ascx has an
event. When I click on the submit linkbutton in the ascx, the event does not fire. But if I click it a second time, it fires.

I put in tracing, and the OnInit (which loads the event handler) is

executed
on the initial load and also on the 2nd. It just makes no sense to

me. Any
ideas?

Thanks a zillion!!

Dan



Nov 18 '05 #4
kw
Well, it didn't work.

ViewState["CtrlId"] is set prior to LoadControl but in the UserControl,
ViewState["CtrlId"] is null.

but what does (sort of) work is using a public property in the Page, setting
the ID into that property prior to LoadControl, and in the control
Page_Load:

MyPage j = (MyPage)this.Pa ge;
this.ID=j.Conte ntID;

Which is a bullshit solution because the UserControl is now specific to this
one page...but it works.
"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
Dan,

That sounds right. Unfortunately, I can't confirm. You'll just have to try a few combinations if the way you've described doesn't work. I'm not even
positive that the ID need be defined in the page load routine. I think you
could also define it in the Page Init.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:uu******** ******@TK2MSFTN GP12.phx.gbl...
AMAZING!!! You were right! I'm still not quite sure why this should be
as it is obvious from my situation that something is very wrong about

this.
See, the same ascx is being loaded by a treeview to display various

objects
represented by different ID's.

On the face of it, it looks like polymorphism is out the window and now I
have to manually create copies of the ascx under different names so I can assign them the appropriate ID in the instantiation.. ..unless there is a

way
to communicate that to the ascx via the viewstate, querystring or some

other
means.

What do you suggest?

To make this concrete, here is where things are now:
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID="MyCont rol1";

But it looks like this is what it should be:
//ASPX
private void TreeViewControl _SelectedIndexC hange(object sender,
System.EventArg s e){
TreeNode n = TreeViewControl .GetNodeFromInd ex(e.NewNode);
ViewState["ContentId"]=n.ID; //or some other node dependent variation
Content.Control s.Add(LoadContr ol(n.ID+".ascx" ));
...
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID=ViewSta te["ContentId"];

That looks about right, right? The idea being that ID has to be assigned in
the ASCX Page_Load and that ViewState is the best means of

communication.
"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
Dan,

The solution for this one isn't obvious.

Make certain that you're specifying your control's ID. That means do

this inside of the control's page load:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

Me.ID = "MyControl1 "

End Sub
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:eU******** *****@TK2MSFTNG P12.phx.gbl...
> My aspx dynamically loads an ascx into a placeholder. The ascx has an > event. When I click on the submit linkbutton in the ascx, the event

does
> not fire. But if I click it a second time, it fires.
>
> I put in tracing, and the OnInit (which loads the event handler) is
executed
> on the initial load and also on the 2nd. It just makes no sense to me. Any
> ideas?
>
> Thanks a zillion!!
>
> Dan
>
>



Nov 18 '05 #5
Dan,

Maybe you could set a property in the parent page's context and then pull
the id from the context object...

ViewState variables are pulled from the page as it's built. So that didn't
work because, until the page is posted the first time, viewstate hasn't been
set yet. But if you add a variable to the page's context object:

Context("CtrlId ") = "Control1";

That should get set immediately and make your control usable across multiple
pages again... (As long as the page set's the control id in the context
object of course.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:OP******** ******@TK2MSFTN GP09.phx.gbl...
Well, it didn't work.

ViewState["CtrlId"] is set prior to LoadControl but in the UserControl,
ViewState["CtrlId"] is null.

but what does (sort of) work is using a public property in the Page, setting the ID into that property prior to LoadControl, and in the control
Page_Load:

MyPage j = (MyPage)this.Pa ge;
this.ID=j.Conte ntID;

Which is a bullshit solution because the UserControl is now specific to this one page...but it works.
"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in message
news:10******** *****@corp.supe rnews.com...
Dan,

That sounds right. Unfortunately, I can't confirm. You'll just have to try
a
few combinations if the way you've described doesn't work. I'm not even
positive that the ID need be defined in the page load routine. I think you could also define it in the Page Init.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"kw" <el************ *****@hotmail.c om> wrote in message
news:uu******** ******@TK2MSFTN GP12.phx.gbl...
AMAZING!!! You were right! I'm still not quite sure why this should
be
as it is obvious from my situation that something is very wrong about this.
See, the same ascx is being loaded by a treeview to display various

objects
represented by different ID's.

On the face of it, it looks like polymorphism is out the window and
now I have to manually create copies of the ascx under different names so I can assign them the appropriate ID in the instantiation.. ..unless there is
a way
to communicate that to the ascx via the viewstate, querystring or some other
means.

What do you suggest?

To make this concrete, here is where things are now:
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID="MyCont rol1";

But it looks like this is what it should be:
//ASPX
private void TreeViewControl _SelectedIndexC hange(object sender,
System.EventArg s e){
TreeNode n = TreeViewControl .GetNodeFromInd ex(e.NewNode);
ViewState["ContentId"]=n.ID; //or some other node dependent variation
Content.Control s.Add(LoadContr ol(n.ID+".ascx" ));
...
//ASCX
private void Page_Load(objec t sender, System.EventArg s e){
this.ID=ViewSta te["ContentId"];

That looks about right, right? The idea being that ID has to be assigned
in
the ASCX Page_Load and that ViewState is the best means of

communication.
"S. Justin Gengo" <sjgengo@aboutf ortunate[no-spam].com> wrote in
message news:10******** *****@corp.supe rnews.com...
> Dan,
>
> The solution for this one isn't obvious.
>
> Make certain that you're specifying your control's ID. That means do

this
> inside of the control's page load:
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArg s) Handles MyBase.Load
>
> 'Put user code to initialize the page here
>
> Me.ID = "MyControl1 "
>
> End Sub
>
>
> --
> Sincerely,
>
> S. Justin Gengo, MCP
> Web Developer / Programmer
>
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzsche
> "kw" <el************ *****@hotmail.c om> wrote in message
> news:eU******** *****@TK2MSFTNG P12.phx.gbl...
> > My aspx dynamically loads an ascx into a placeholder. The ascx has an > > event. When I click on the submit linkbutton in the ascx, the

event does
> > not fire. But if I click it a second time, it fires.
> >
> > I put in tracing, and the OnInit (which loads the event handler) is > executed
> > on the initial load and also on the 2nd. It just makes no sense

to me.
> Any
> > ideas?
> >
> > Thanks a zillion!!
> >
> > Dan
> >
> >
>
>



Nov 18 '05 #6

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

Similar topics

7
3259
by: Tim T | last post by:
Hi, I have the need to use dynamically loaded user controls in a webform page. I have the controls loading dynamically, and that part works fine. this is the code used in a webform to dynamically load one of several controls: private void btnCategory_Click(object sender, System.EventArgs e) { Control myControl = LoadControl(DropDownList1.SelectedItem.Text + ".ascx"); PlaceHolder1.Controls.Add(myControl);
8
4314
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image button at runtime: //----- Code snippet protected System.Web.UI.WebControls.PlaceHolder ImageHolder; private void Page_Load(object sender, System.EventArgs e)
5
1715
by: karthick raja | last post by:
Am experiencing a problem intercepting the events from controls added dynamically to a Placeholder control at runtime. Is there any way that I can write an event handler on the page which will be pick up the events raised by the added controls dynamically. I cannot use 'WithEvents' and 'Handles' because this requires that the controls be declared on the page and they aren't (they are created in the external class) I did think of using...
0
1211
by: Dan | last post by:
hi, i have a page with two usercontrols: 1. a static menu control. 2. a dynamically loaded control as user interface the main page receives events from the menu and sets the apropriate ui control in the OnBubbleEvent method. but now, the ui control doesnt't fire any events any more. i first have to do another postback, and now the ui fires again. what's wrong there?
1
1358
by: Darrel | last post by:
I have a usercontrol that is dynamically loaded. Within this usercontrol, I want to add some javascript, and then attach it to one of the web controls on this page. Normally, I'd just use something like this: RequiredFieldValidator_description.Attributes.Add("onKeyUp", "textCounter(this,299);") But this does not work for some reason. I assume it's because of the dynamic
5
2345
by: Alan Silver | last post by:
Hello, I have a products page that takes a product ID in the query string. Based on the product details (from a database), the page then loads up one of a number of custom controls, calls a method in the control (that displays product info) and then loads the control into a placeholder so it will be displayed. I want to be able to restore the state of the controls in the custom control, but can't get it to work. For example, the...
0
1168
by: Jesper Lund Stocholm | last post by:
I have problems with sending javascript to the client from a dynamically loaded usercontrol. I have a single page that dynamically loads controls into a table cell in a HTML-table. For one of these controls I would like to add some javascript to the page loading my control. The problem is only - nothing happens. The code that loads my usercontrol from my ASPX-page is: tdContent.Controls.Add(Page.LoadControl(contentControl));
1
1472
by: Alexey Smirnov | last post by:
I have a web form, which load a web control by using the LoadControl method void Page_Init(...) { Control ctl = LoadControl(Request.QueryString+".ascx"); // url = default.aspx?module=control1 Panel1.Controls.Add(ctl); }
1
2786
by: Sami Rehman | last post by:
Hi, I am creating some web user controls dynamically Using LoadControl("ABC.ascx") My user control contains 2 drop down list, 2nd one is loaded based on the selection in the 1st one. However whenever I make the selection in the 1st one, the control disappears after the post back. I tried setting the EnableViewState=true but even that did not help.. UCTemp ucTemp = (UCTemp)LoadControl("UCTemp.ascx");
0
8946
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
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
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
6031
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.