DYNAMIC TEXT BOX CONTROL

Posted by Nksingh420 under ASP.NET on 7/13/2013 | Points: 10 | Views : 1587 | Status : [Member] | Replies : 5
i am creating dynamic text box control and add in Panel but i am not getting the value which i entered in text box after submit button




Responses

Posted by: Venkat0454 on: 7/13/2013 [Member] Starter | Points: 25

Up
0
Down
public partial class Default6 : System.Web.UI.Page

{
TextBox txt123;
protected void Page_Load(object sender, EventArgs e)
{
txt123 = new TextBox();
Panel1.Controls.Add(txt123);

}


protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(txt123.Text);
}
}


Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabu_Spark on: 7/13/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Venkat,
Put IsPostBack condition to avoid postback on button click. If you click the button again the form
get loaded and values will be cleared. So you will not get the values of textbox. Kindly give me the
valuable feedback about my code.


Try the below the code:

public partial class Default6 : System.Web.UI.Page
{
TextBox txt123;
protected void Page_Load(object sender, EventArgs e)
{
if( !isPostBack)
{
txt123 = new TextBox();
Panel1.Controls.Add(txt123);
}
}

protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(txt123.Text);
}

}




With regards,
J.Prabu.
[Email:prbspark@gmail.com]

Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nksingh420 on: 7/13/2013 [Member] Starter | Points: 25

Up
0
Down
My Code is ......
I have Two Button , one for Create Dynamic Text Box and One Button for Show The Value of Textbox.
protected void btnDyn_Click(object sender, EventArgs e)
{
TextBox txt = new TextBox();
txt.Text = "";
txt.ID = "TextBox10";
txt.Width = 560;
txt.Height = 48;
panel1.Controls.Add(txt);
}

protected void btnShow_Click(object sender, EventArgs e)
{
TextBox t1 = (TextBox)panel1.FindControl("TextBox10");
lblshow.Text = "Text is " + t1.Text;
}


But t1 has null value

Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nksingh420 on: 7/13/2013 [Member] Starter | Points: 25

Up
0
Down
any body have code for create dynamic textbox and display textbox data in asp.net

Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Venkat0454 on: 7/15/2013 [Member] Starter | Points: 25

Up
0
Down


public partial class Default6 : System.Web.UI.Page

{
TextBox txt;

protected void Page_Load(object sender, EventArgs e)
{
CreateTextBox("txtDynamic");
Control f = FindControl("txtDynamic");
f.Visible = false;
}

private void CreateTextBox(string ID)
{
txt = new TextBox();
txt.ID = ID;
PlaceHolder1.Controls.Add(txt);
}

protected void btnDyn_Click(object sender, EventArgs e)
{
CreateTextBox("txtDynamic");
}

protected void Button2_Click(object sender, EventArgs e)
{
Response.Write(txt.Text);
CreateTextBox("txtDynamic");
}
}


Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response