RE: Adding Controls to a Page 2005-02-22 - By Joe Bradvica
You have to re-add the controls on postback. The data is then repopulated to the controls and you can access the data.
Joe B.
-----Original Message----- From: Boudreau, Duane [mailto:BoudreauD@(protected)] Sent: Tuesday, February 22, 2005 11:28 AM To: aspnet-controlbuilding@(protected) Subject: [aspnet-controlbuilding] RE: Adding Controls to a Page
I added a table place holder and added the controls on the fly and it works fine, except when I submit the page the controls no longer exist. Any idea what needs to be done to get the controls to be displayed on the submit page? Also how are the control values accesses in the post back?
int x = 0; while (qryPM.Read()) { TableRow tr = new TableRow(); CheckBox cb = new CheckBox(); cb.ID = "cbxPM:" + qryPM["f1"].ToString(); cb.Text = qryPM["f2"].ToString();
TextBox tb = new TextBox(); tb.ID = "txtPMQty:" + qryPM["f1"].ToString(); tb.CssClass = "inputControl"; tb.Width = System.Web.UI.WebControls.Unit.Parse("30px",System.Globalization.Culture Info.InvariantCulture);
Label lb = new Label(); lb.ID = "lblPM" + x.ToString(); lb.Text = " " + qryPM["f3"].ToString();
TableCell tc1 = new TableCell(); tc1.Controls.Add(cb); tr.Cells.Add(tc1);
TableCell tc2 = new TableCell(); tc2.Controls.Add(tb); tr.Cells.Add(tc2);
TableCell tc3 = new TableCell(); tc3.Controls.Add(lb); tr.Cells.Add(tc3);
tblPM.Rows.Add(tr); x++; }
-----Original Message----- From: Sonu Kapoor [mailto:sonukapoor@(protected)] Sent: Friday, February 18, 2005 6:15 PM To: aspnet-controlbuilding@(protected) Subject: [aspnet-controlbuilding] RE: Adding Controls to a Page
You can also use a PlaceHolder. Something like this:
Label lbl = new Label; lbl.Text = "test";
placeholder.controls.add(lbl);
-- Sonu Kapoor WebSite: http://www.Kapoorsolutions.com Blog: http://www.Kapoorsolutions.com/blog/
On Fri, 18 Feb 2005 18:11:20 -0500, James Shaw <james@(protected)> wrote: > Usually you have a container like an <asp:panel> or <asp:literal> on the > page, and then add controls to it with .Controls.Add() from codebehind > > Best regards, > James Shaw > 2005 Microsoft MVP ASP.NET > www.CoverYourASP.NET > Blogging on ASP.NET > www.CoverYourASP.com > Download it. Run it. Learn it. > www.DozingDogs.com > Over 50 million pages served > > > -----Original Message----- > From: Boudreau, Duane [mailto:BoudreauD@(protected)] > Sent: Friday, February 18, 2005 4:30 PM > To: aspnet-controlbuilding@(protected) > Subject: [aspnet-controlbuilding] Adding Controls to a Page > > Using C#, is there a way to dynamically add controls (labels, textboxes, > etc) to a page in its code behind page? > > If so can someone point me to a tutorial or some sample code? > > Thanks, > Duane > > Need SQL Advice? http://sqladvice.com > Need RegEx Advice? http://regexadvice.com Need XML Advice? > http://xmladvice.com > > Need SQL Advice? http://sqladvice.com > Need RegEx Advice? http://regexadvice.com Need XML Advice? > http://xmladvice.com >
Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com
Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com
Need SQL Advice? http://sqladvice.com Need RegEx Advice? http://regexadvice.com Need XML Advice? http://xmladvice.com
|
|