473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Accessing the page from dynamically loaded control

I have a web form, which load a web control by using the LoadControl
method

void Page_Init(...)
{
Control ctl = LoadControl(Request.QueryString["module"]+".ascx"); //
url = default.aspx?module=control1
Panel1.Controls.Add(ctl);
}

Now, I want to add to the web form a DropDownList control, which
should interact with the web control.

void Page_Load(...)
{
DropDownList ddl = new DropDownList();
ddl.DataSource = ...
ddl.DataBind();

ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(IndexChanged);
}

void IndexChanged(object sender, EventArgs e)
{
Session["MY_KEY"] = ((DropDownList)sender).SelectedItem.Value;
}

and now I want to use an actual value of the DropDownList (or a
session key) in the web control

void Page_Load()
{
Response.Write(Session["MY_KEY"]);
}

The problem is here that when the selected item in the DropDownList
has been changed, the sequence is following:

webform.init/load
webcontrol.load
webform.IndexChanged

And finally the rendered page shows the "old" Session["MY_KEY"]
because the IndexChanged has been executed after the contol is loaded.

So, how do I get the actual value of the DropDownList inside the web
control?

Mar 27 '07 #1
1 1462
On Mar 27, 2:12 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
I have a web form, which load a web control by using the LoadControl
method

void Page_Init(...)
{
Control ctl = LoadControl(Request.QueryString["module"]+".ascx"); //
url = default.aspx?module=control1
Panel1.Controls.Add(ctl);

}

Now, I want to add to the web form a DropDownList control, which
should interact with the web control.

void Page_Load(...)
{
DropDownList ddl = new DropDownList();
ddl.DataSource = ...
ddl.DataBind();

ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(IndexChanged);

}

void IndexChanged(object sender, EventArgs e)
{
Session["MY_KEY"] = ((DropDownList)sender).SelectedItem.Value;

}

and now I want to use an actual value of the DropDownList (or a
session key) in the web control

void Page_Load()
{
Response.Write(Session["MY_KEY"]);

}

The problem is here that when the selected item in the DropDownList
has been changed, the sequence is following:

webform.init/load
webcontrol.load
webform.IndexChanged

And finally the rendered page shows the "old" Session["MY_KEY"]
because the IndexChanged has been executed after the contol is loaded.

So, how do I get the actual value of the DropDownList inside the web
control?
Well, found one possible solution to use the Page_PreRender in a web
control (instead the Page_Load).

void Page_PreRender()
{
Response.Write(Session["MY_KEY"]);
}

Any other ideas?

Mar 27 '07 #2

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

Similar topics

6
by: Earl Teigrob | last post by:
I am writing an application that dynamically loads user controls at run time based on user options. I would like to give my users the ability to build their own user controls and add them to my...
1
by: Greg | last post by:
In my ASP.NET application I have a button that when pressed, data needs to be saved based on what the user typed in. I have other controls on the same page that should be updated as a result of the...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
1
by: Jeff Smith | last post by:
Can I load custom web user controls dynamically and access the properties and methods without having to explicitly define custom control types (example 2 below). I have custom web control named...
2
by: Chris Kettenbach | last post by:
Good Morning, I have a user control I dynamically load in the page_init event into a asp:placeholder control. This page also has another placeholder I would like to dynamically load controls into...
3
by: Jordan | last post by:
My ASP.NET 1.1. app dynamically loads a user control into a PlaceHolder control that exists in an aspx page. The user control is loaded during the Page_Load event of the aspx. The PlaceHolder's...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
0
by: erkbiz | last post by:
Hello, this is my first post, I hope this is the right forum to ask my question. I am dynamically loading a user control multiple times. I have a gridview and have inserted empty rows. Into these...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.