473,761 Members | 4,407 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamically created control disappears after postback.

Hi,
I am creating some web user controls dynamically Using
LoadControl("AB C.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)LoadCon trol("UCTemp.as cx");
ucTemp.EnableVi ewState = true;
plhInput.Contro ls.Add(ucTemp);

Does any one know why this is happening?

-Sami
Sep 3 '07 #1
1 2788
"Sami Rehman" <sa*********@4D .orgwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
Does any one know why this is happening?
Dynamically created controls do not survive a postback - they need to be
recreated each time the page loads, irrespective of how it loads.

In addition, if they need to be wired up to events, they need to be created
before the Page_Load event e.g. in the Page_Init event...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 3 '07 #2

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

Similar topics

8
4315
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)
1
1876
by: powerranger | last post by:
I have a web page where I have dropdownlist box with autopostback set to true. The box has 3 items: 1, 2, and 3. I also have a Placeholder and a button. Each time the user change the value of the dropdownlist, I create dynamically one or x text box. Here is my code... for (int i = 0; i < Convert.ToInt32(ddListsRpt.SelectedValue); i++) { TextBox txtbx = new TextBox(); txtbx.Visible = true;
2
1947
by: djc | last post by:
On the page_load event I am querying a database and binding data to some text boxes, list boxes, and a repeater control. When the page loads it uses the value of one of the database fields (status) to determine what options should be available for this particular item (which is an issue... small issue tracking system). Each of these options is an action that may be performed on the issue and I am dynamically creating LinkButtons for each...
1
3414
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a value to the td.innerHTML property. The UI is done, and I now want to post back the user's changes and update my business object in .NET. But when I postback, I can't see any of my dynamically created HTML controls in VB .NET. How do I make them...
0
1351
by: news.zen.co.uk | last post by:
Hi Guys, Using VB .NET 2003 and ASP1.1, I have a Datagrid embedded in an ASP page. In the processing of the ItemDataBound event I dynamically create a new Datagrid control within the Cell of the Parent (this refelect GUI'wise a Parent Child related data). I also add Handlers to the sub datagrid using AddHandler to handle the EditCommandColumn as well as ItemDataBound. Parent Datagrid...
9
7928
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview contains a placeholder and I add the control to it, the user control is a formview bound to an object datsource. This works great until I post back the page and the user control disappears. What am I doing wrong? Regards, Chris. Protected Sub...
2
11987
by: ami | last post by:
In my code, I need to implement x numbers of Gridviews dynamically based on user selection. Because I am unaware of the number of gridviews, this is done after the user enters input. I need to implement paging on these gridviews. I set paging to true and register the event handler. However, this event handler is never being fired (this has been tested by using the VS2005 debugger). My first page of results shows up fine. When a page...
4
2973
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a while and it seems it's not possible because the row that gets added with each click won't get recreated after a post back. After all the reading it seems that any dynamically created controls must be created in the Init event to be recreated after...
4
11010
by: Craig Buchanan | last post by:
I dynamically add data-bound templates to a gridview in my ascx control. while this works correctly when the gridview is databound to the datatable, i'm having issues on postback. i would like to iterate thru the gridview's rows, examine the databound controls, then perform a database action. for some reason, i can't find the controls. i have a two templates: one that uses a label the other uses a textbox to display data. when the...
0
9345
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
10115
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
9957
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
9905
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
8780
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...
0
6609
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();...
1
3881
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
3
3456
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2752
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.