| | |
Adding Controls Dynamically (URGENT)
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2006
Posts: 3
Reputation:
Solved Threads: 0
I have to create a number of controls equal to a number entered in a textbox by the user. I created a web user control, which has a radio button list. Then when the user press a Submit button, I want to check the selected values of the controls created dynamically, but the problem is that they are removed on post-back.
I managed with the aid of an article I read on the net (http://www.tgreer.com/aspnet_html_04.html), to maintain the controls created dynamically after post back, but still one problem I have is the values the user enters in the dynamically created controls is lost after post back.
Here is my code:
I managed with the aid of an article I read on the net (http://www.tgreer.com/aspnet_html_04.html), to maintain the controls created dynamically after post back, but still one problem I have is the values the user enters in the dynamically created controls is lost after post back.
Here is my code:
ASP.NET Syntax (Toggle Plain Text)
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class questions : System.Web.UI.Page { void Page_Load(object sender, EventArgs e) { if (!=IsPostBack) { ViewState.Add("mode", "0"); } } protected override void LoadViewState(object savedState) { base.LoadViewState(savedState); if (ViewState["mode"].ToString() == "1") { CreateControls(); } } protected void BTN_Submit_Click(object sender, EventArgs e) { if (TextBox1.Text != "") { for (int i = 0; i < int.Parse(TextBox1.Text); i++) { ASP.mcq_ascx newc = new ASP.mcq_ascx(); newc.ID = "newc" + i.ToString(); this.Q_PlaceHolder.Controls.Add(newc); } } } protected void BTN_Result_Click(object sender, EventArgs e) { CreateControls(); ViewState.Add("mode", "1"); } protected void CreateControls() { if (TextBox1.Text != "") { for (int i = 0; i < int.Parse(TextBox1.Text); i++) { ASP.mcq_ascx newc = new ASP.mcq_ascx(); newc.ID = "newc" + i.ToString(); this.Q_PlaceHolder.Controls.Add(newc); } } } }
![]() |
Similar Threads
- dynamically adding controls to report (Visual Basic 4 / 5 / 6)
- adding controls dynamically (VB.NET)
- Reading Controls from Panel (ASP.NET)
- Wizard COntrol: Adding steps dynamically and keeping state (ASP.NET)
- Using Windows XP Visual Styles with Controls on Windows Forms (VB.NET)
- Adding controls into a ListView (Visual Basic 4 / 5 / 6)
Other Threads in the ASP.NET Forum
- Previous Thread: username after /
- Next Thread: active row
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 ajax appliances application asp asp.net beginner box browser businesslogiclayer button c# cac checkbox child class compatible complex content contenttype control countryselector courier database datagrid datagridview datalist deployment development dgv dialog dropdown dropdownmenu dynamic dynamically edit editing embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv folder form gridview gudi iis image javascript list maps menu mobile mssql nameisnotdeclared novell opera order parent problem ratings redirect refer registration relationaldatabases reportemail response.redirect rows search security select serializesmo.table sessionvariables silverlight smoobjects software sql sql-server ssl tracking treeview typeof validatedate validation vb.net vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming wizard xsl





