How to get the value of a dynamically created textBox in asp.net C#?
-
I have Created textbox, dropDownList Dynamically at run time.Now how do i get the textbox value and dropDown value in ButtonClick.
-
I have Created textbox, dropDownList Dynamically at run time.Now how do i get the textbox value and dropDown value in ButtonClick.
Can you give your sample code, for us its logic flow analysis, or you did not make his code..??
-
Can you give your sample code, for us its logic flow analysis, or you did not make his code..??
TextBox txt = new TextBox(); txt.ID = ID; txt.Text = DateTime.Now.ToString(); PlcHolder.Controls.Add(txt); DropDownList ddl = new DropDownList(); ddl.ID = ID; string strSql = "SELECT Code,[Name] FROM SDTS_GSTYPE"; DataTable dtBranch = getDataTable(strSql); ddl.DataSource = dtBranch; ddl.AutoPostBack = true; ddl.DataTextField = "Name"; ddl.DataValueField = "Code"; ddl.SelectedIndex = 0; ddl.DataBind(); PlcHolder.Controls.Add(ddl); This is the code i have written to create a textbox.Now how do i get the textbox value and selected value of dropDownlist in my buttonClick event.
-
TextBox txt = new TextBox(); txt.ID = ID; txt.Text = DateTime.Now.ToString(); PlcHolder.Controls.Add(txt); DropDownList ddl = new DropDownList(); ddl.ID = ID; string strSql = "SELECT Code,[Name] FROM SDTS_GSTYPE"; DataTable dtBranch = getDataTable(strSql); ddl.DataSource = dtBranch; ddl.AutoPostBack = true; ddl.DataTextField = "Name"; ddl.DataValueField = "Code"; ddl.SelectedIndex = 0; ddl.DataBind(); PlcHolder.Controls.Add(ddl); This is the code i have written to create a textbox.Now how do i get the textbox value and selected value of dropDownlist in my buttonClick event.
sorry, long time to replay...... first, The first, you should know basic first Page Postback ... every time you create dynamic controls in codebehind, even when you do click on a control button, the page is always postback, and automatically you will never get the value out of control, even control was not there at all when you try to use the event FinControl ... so, you have to declare the event re-create control when page IsPostBack. This sample code to start what you want .. this is just a beginning to open its forward your logic .. you can add it from the code sample I gave .....
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack) //this first time page Load/isPostback when call this page
{
GenerateControlSelf();//for generate custom control in holder(as PlaceHolder)
}
else //second Page.isPostback
{
// you must declare again your custom control in second Page.isPostback
var txt = new TextBox { ID = "tbx", Text = DateTime.Now.ToString(CultureInfo.InvariantCulture), ClientIDMode = ClientIDMode.Static };
holder.Controls.Add(txt);
var ddl = new DropDownList { ID = "ddlx" };var nextYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) + 1; var lastYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) - 10; for (var n = lastYear; n < nextYear; n++) { ddl.Items.Add(n.ToString(CultureInfo.InvariantCulture)); } ddl.AutoPostBack = true; ddl.SelectedIndex = 0; ddl.DataBind(); holder.Controls.Add(ddl); } } private void GenerateControlSelf() { var txt = new TextBox { ID = "tbx", Text = DateTime.Now.ToString(CultureInfo.InvariantCulture) ,ClientIDMode = ClientIDMode.Static}; holder.Controls.Add(txt); var ddl = new DropDownList {ID = "ddlx"}; var nextYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) + 1; var lastYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) - 10; for (var n = lastYear; n < nextYear; n++) { ddl.Items.Add(n.ToString(CultureInfo.Inva
-
sorry, long time to replay...... first, The first, you should know basic first Page Postback ... every time you create dynamic controls in codebehind, even when you do click on a control button, the page is always postback, and automatically you will never get the value out of control, even control was not there at all when you try to use the event FinControl ... so, you have to declare the event re-create control when page IsPostBack. This sample code to start what you want .. this is just a beginning to open its forward your logic .. you can add it from the code sample I gave .....
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack) //this first time page Load/isPostback when call this page
{
GenerateControlSelf();//for generate custom control in holder(as PlaceHolder)
}
else //second Page.isPostback
{
// you must declare again your custom control in second Page.isPostback
var txt = new TextBox { ID = "tbx", Text = DateTime.Now.ToString(CultureInfo.InvariantCulture), ClientIDMode = ClientIDMode.Static };
holder.Controls.Add(txt);
var ddl = new DropDownList { ID = "ddlx" };var nextYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) + 1; var lastYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) - 10; for (var n = lastYear; n < nextYear; n++) { ddl.Items.Add(n.ToString(CultureInfo.InvariantCulture)); } ddl.AutoPostBack = true; ddl.SelectedIndex = 0; ddl.DataBind(); holder.Controls.Add(ddl); } } private void GenerateControlSelf() { var txt = new TextBox { ID = "tbx", Text = DateTime.Now.ToString(CultureInfo.InvariantCulture) ,ClientIDMode = ClientIDMode.Static}; holder.Controls.Add(txt); var ddl = new DropDownList {ID = "ddlx"}; var nextYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) + 1; var lastYear = Convert.ToInt32(DateTime.Now.Year.ToString(CultureInfo.InvariantCulture)) - 10; for (var n = lastYear; n < nextYear; n++) { ddl.Items.Add(n.ToString(CultureInfo.Inva
Thank you very much. Its working.
-
Thank you very much. Its working.
here i am wellcaom..be happy, do not ever hesitate to ask questions and share your knowledge if you already master ..