Working with dynamically created controls
-
You then should be able to do
ctrl.Text=".... "
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
Paul Conrad wrote:
You then should be able to do ctrl.Text=".... "
a cast is needed I guess
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
You then should be able to do
ctrl.Text=".... "
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
Thanks, I have tried out, but there is no such property
-
Paul Conrad wrote:
You then should be able to do ctrl.Text=".... "
a cast is needed I guess
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
N a v a n e e t h wrote:
a cast is needed I guess
Not really. I just tried it and works fine here.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Anuradha612 wrote:
how do i retreive the text stored in text box and value selected in the combo.
Adding to Paul's post, are you getting some problem when retrieving value ? If you are not getting the value entered, check the event where you create dynamic controls. It should be before ASP.NET loads the
viestate
.Init
would be appropriate for dynamic controls.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
Yes, i am unable to retreive the value entered, Pls can you be more clear, with the last post, i am unable to understand,
-
N a v a n e e t h wrote:
a cast is needed I guess
Not really. I just tried it and works fine here.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
Paul Conrad wrote:
Not really. I just tried it and works fine here.
I think I miss something. But I am unable to get
Text
property forControl
instance as you told.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Paul Conrad wrote:
Not really. I just tried it and works fine here.
I think I miss something. But I am unable to get
Text
property forControl
instance as you told.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
I made a mistake by doing a winform and not a webform :-O You can get it in a winform but not webform.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Hi, I have an appln where in i need to create, text boxes and drop downlists dynamically, the issue here is, how do i retreive the text stored in text box and value selected in the combo. Thanks in advance
Hi You are dynamically created textbox like this.
Dim fldMetadata As TextBox fldMetadata = New TextBox fldMetadata.ID = "txtID" Panel1.Controls.Add(fldMetadata)
There should be number of text box. When u creating the control dynamically the u cannot specify same id to all control. u have assign unique id to all textbox in page which u create dynamically. R u creating control dynamically in for loop? Can u paste code here? Regards. RahulPeople Laugh on me Because i am Different but i Laugh on them Because they all are same.
-
Yes, i am unable to retreive the value entered, Pls can you be more clear, with the last post, i am unable to understand,
This is a viewstate issue. Hope you know about
viewstates
. It's mechanism used to keep data across postbacks. For solving the problem, overrideoninit
event and add your controls over there. Then ASP.NET will maintain viewstate for the control and you can get it fromControls
collection.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Hi, I have an appln where in i need to create, text boxes and drop downlists dynamically, the issue here is, how do i retreive the text stored in text box and value selected in the combo. Thanks in advance
Look at this example I create two textboxes and dropdownlist on page load event. I have one Button and one placeholder on the page. On page load event,add all dynamically created in place holder and on button click event, I get values of the textboxes and selected value of dropdownlist.
protected void Page_Load(object sender, EventArgs e) { CreateControls(); } public void CreateControls() { TextBox MyTxt1=new TextBox(); MyTxt1.ID = "MyTxt1"; TextBox MyTxt2 = new TextBox(); MyTxt2.ID = "MyTxt2"; DropDownList MyDDL1 = new DropDownList(); MyDDL1.ID = "MyDDL1"; MyDDL1.Items.Add(new ListItem("1", "1")); MyDDL1.Items.Add(new ListItem("2", "2")); DropDownList MyDDL2 = new DropDownList(); MyDDL2.ID = "MyDDL2"; MyDDL2.Items.Add(new ListItem("1", "1")); MyDDL2.Items.Add(new ListItem("2", "2")); PL.Controls.Add(MyTxt1); PL.Controls.Add(MyTxt2); PL.Controls.Add(MyDDL1); PL.Controls.Add(MyDDL2); } protected void MyButton_Click(object sender, EventArgs e) { string myText1 = ((TextBox)this.Page.FindControl("MyTxt1")).Text; string myText2 = ((TextBox)this.Page.FindControl("MyTxt2")).Text; string myDDL1 = ((DropDownList)this.Page.FindControl("MyDDL1")).SelectedValue; string myDDL2 = ((DropDownList)this.Page.FindControl("MyDDL2")).SelectedValue; Response.Write("Value 1 : " + myText1 + " Value 2: " + myText2 + " Value 3 :" + myDDL1 + " Value 4: " + myDDL2); }
please don't forget to vote on the post that helped you.
-
Hi You are dynamically created textbox like this.
Dim fldMetadata As TextBox fldMetadata = New TextBox fldMetadata.ID = "txtID" Panel1.Controls.Add(fldMetadata)
There should be number of text box. When u creating the control dynamically the u cannot specify same id to all control. u have assign unique id to all textbox in page which u create dynamically. R u creating control dynamically in for loop? Can u paste code here? Regards. RahulPeople Laugh on me Because i am Different but i Laugh on them Because they all are same.
rahul.net11 wrote:
Can u paste code here?
He did, in his second post[^] in the thread.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Look at this example I create two textboxes and dropdownlist on page load event. I have one Button and one placeholder on the page. On page load event,add all dynamically created in place holder and on button click event, I get values of the textboxes and selected value of dropdownlist.
protected void Page_Load(object sender, EventArgs e) { CreateControls(); } public void CreateControls() { TextBox MyTxt1=new TextBox(); MyTxt1.ID = "MyTxt1"; TextBox MyTxt2 = new TextBox(); MyTxt2.ID = "MyTxt2"; DropDownList MyDDL1 = new DropDownList(); MyDDL1.ID = "MyDDL1"; MyDDL1.Items.Add(new ListItem("1", "1")); MyDDL1.Items.Add(new ListItem("2", "2")); DropDownList MyDDL2 = new DropDownList(); MyDDL2.ID = "MyDDL2"; MyDDL2.Items.Add(new ListItem("1", "1")); MyDDL2.Items.Add(new ListItem("2", "2")); PL.Controls.Add(MyTxt1); PL.Controls.Add(MyTxt2); PL.Controls.Add(MyDDL1); PL.Controls.Add(MyDDL2); } protected void MyButton_Click(object sender, EventArgs e) { string myText1 = ((TextBox)this.Page.FindControl("MyTxt1")).Text; string myText2 = ((TextBox)this.Page.FindControl("MyTxt2")).Text; string myDDL1 = ((DropDownList)this.Page.FindControl("MyDDL1")).SelectedValue; string myDDL2 = ((DropDownList)this.Page.FindControl("MyDDL2")).SelectedValue; Response.Write("Value 1 : " + myText1 + " Value 2: " + myText2 + " Value 3 :" + myDDL1 + " Value 4: " + myDDL2); }
please don't forget to vote on the post that helped you.
Why the example in C#? The OP posted his code and he was doing it in VB. See his second post[^] in the thread...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon