Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 04, 2010 07:01 PM by mangesh.singh
Apr 08, 2008 10:49 PM|LINK
Whether the Page.IsPostBack property returns true or false is usually not the issue. The page might be in a postback and still not need to have any dynamic controls loaded. It might require a specific interaction with the page that causes the first dynamic
control to be loaded. Ultimately, it is important to keep track of what dynamic controls (if any) may have been loaded and then continue to load them early in the page life-cycle on all subsequent postbacks.
Apr 20, 2008 09:50 AM|LINK
This subject is always problematic to the beginner asp.net developers and this post does a good job clearing things out.
May 07, 2008 10:08 AM|LINK
Hi , i want to ask something related to this thread.
I want to add a new DropDownList to a panel only when user clicks button "Add New", and add an event handler CheckedChanged to this control.
I also want to have the viewstate of every dropdownlist i have already added in order to use it when user clicks "Submit" (another button).
I figured out that the solution is ( according to lifecycle of aspx page ) :
if (Session["countDDL"] == null)
Session["countDDL"] = 0;
Session["countDDL"] = int.Parse(Session["countDDL"].ToString()) + 1;
for (int i = 0; i < int.Parse(Session["countDDL"].ToString()); i++)
DropDownList processes = new DropDownList();
ListItem lsi = new ListItem("Choose ");
processes.ID = "processes" + i.ToString();
processes.Width = 150;
processes.AutoPostBack = true;
processes.SelectedIndexChanged += new EventHandler(processes_SelectedIndexChanged);
Create and fill all the dropdownlists that exist plus one more . The Viewstate works fine if the IDs are the same.
Session["buttonAddNewPressed"] = false;
Reset Session key.
protected void AddNewProcess_Click(object sender, ImageClickEventArgs e)
Session["buttonAddNewPressed"] = true;
protected void Page_PreRender(object sender, EventArgs e)
if ((bool)Session["buttonAddNewPressed"] == false)
Session["countDDL"] = int.Parse(Session["countDDL"].ToString()) - 1;
If Button "Add New" didn't press i delete the last dropdownlist beacuse another event happened and decrease the session counter by one.
My question is " Can i make my code better ?" , i don't want to create and delete controls after . I decided to do this because the "Add New" Event fires between Page_Load and PreRender steps and the only way to create a control that its handlers are registered
is to create before PreRender. So I create it at Init It could be in Page_Load as well and then if the button pressed i don't delete it.
Thanx in advance,
May 10, 2008 12:01 AM|LINK
When I first started working with the Accordian control in an update Panel I had this issue. I was data binding a lot of things so as a result, I kept having to use a lot of caching in order to not over hit the database but also to retain the controls
on the page. This is a pretty good way to do it from what I see. I need to figure out VB a bit more as I really only us C#.
Oct 17, 2008 06:47 PM|LINK
This is amazing article explaing in detail how to get the dynamic controls value after the potback occurs.
I am working on C# and I can't seem to find AddHadler and could't convert your code to C# because of other issues. Can you please detail me how do I convert your code into C# or if you have a C# version of the above code, can you please provide me.
Dec 17, 2008 02:29 AM|LINK
I am having a dropdownlist when I am assigning the values to it as shown below it is working fine when I am retreiving the value in other control events.
drSocket.DataSource = dsSocket
drSocket.DataTextField = "SOCKET"
drSocket.DataValueField = "SOCKET"
But if I am assigning the values as below it is not allowing me to read the .selected value. it returns ""
drSocket.Items.Add(New ListItem(strSelect, strSelect))
For Each dr As DataRow In dsSocket.Tables(0).Rows
drSocket.Items.Add(New ListItem(dr.Item("SOCKET"), dr.Item("SOCKET")))
I am using DirectCast(item.FindControl("drSocket"), DropDownList).SelectedValue to retreive the value in other events.
They this is happening?
Drop down list
Dec 25, 2008 04:49 AM|LINK
Nice post, this issue always consufe every new asp.net developer. This post will be a usefull link for them.
Jan 01, 2009 05:31 AM|LINK
Feb 12, 2009 09:52 AM|LINK
i want to create dynamic controls mainly textbox and can be any number
i have created it dynamically and assign id to them but when i enter values in these textboxes
i cant read them on button click.
So how to retrive values from dynamically created textboxes on button click
Thanks in Advance
Mar 20, 2009 11:41 AM|LINK
but in onClick() method if i want to assign value say integer value=90 or a string "xyz" to the textbox
it not works .value not be able to assign, Can u give some solution ?
asp with c#.net