filmov
tv
Loading controls dynamically in asp.net Part 110

Показать описание
Text version of the video
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In this video we will discuss about
1. Adding controls dynamically
2. Tips and tricks to maintain the state of dynamically added controls across postback
To maintain the state of controls across postback
1. Add the controls in the page load event, and set their visibility to false.
2. Based on the DropDownList selection, show/hide the dynamically added controls
For the HTML and code samples used in the demo please visit my blog at the following link
Code Behind Code
protected void Page_Load(object sender, EventArgs e)
{
TextBox TB = new TextBox();
TB.ID = "TB1";
PlaceHolder1.Controls.Add(TB);
TB.Visible = false;
DropDownList DDL = new DropDownList();
DDL.ID = "DDL1";
DDL.Items.Add("New York");
DDL.Items.Add("New Jersey");
DDL.Items.Add("Washington DC");
PlaceHolder1.Controls.Add(DDL);
DDL.Visible = false;
if (DropDownList1.SelectedValue == "TB")
{
TB.Visible = true;
}
else if (DropDownList1.SelectedValue == "DDL")
{
DDL.Visible = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "TB")
{
Response.Write(((TextBox)PlaceHolder1.FindControl("TB1")).Text);
}
else if (DropDownList1.SelectedValue == "DDL")
{
Response.Write(((DropDownList)PlaceHolder1.FindControl("DDL1")).SelectedItem.Text);
}
}
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
Slides
All ASP .NET Text Articles
All ASP .NET Slides
All Dot Net and SQL Server Tutorials in English
All Dot Net and SQL Server Tutorials in Arabic
In this video we will discuss about
1. Adding controls dynamically
2. Tips and tricks to maintain the state of dynamically added controls across postback
To maintain the state of controls across postback
1. Add the controls in the page load event, and set their visibility to false.
2. Based on the DropDownList selection, show/hide the dynamically added controls
For the HTML and code samples used in the demo please visit my blog at the following link
Code Behind Code
protected void Page_Load(object sender, EventArgs e)
{
TextBox TB = new TextBox();
TB.ID = "TB1";
PlaceHolder1.Controls.Add(TB);
TB.Visible = false;
DropDownList DDL = new DropDownList();
DDL.ID = "DDL1";
DDL.Items.Add("New York");
DDL.Items.Add("New Jersey");
DDL.Items.Add("Washington DC");
PlaceHolder1.Controls.Add(DDL);
DDL.Visible = false;
if (DropDownList1.SelectedValue == "TB")
{
TB.Visible = true;
}
else if (DropDownList1.SelectedValue == "DDL")
{
DDL.Visible = true;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "TB")
{
Response.Write(((TextBox)PlaceHolder1.FindControl("TB1")).Text);
}
else if (DropDownList1.SelectedValue == "DDL")
{
Response.Write(((DropDownList)PlaceHolder1.FindControl("DDL1")).SelectedItem.Text);
}
}
Комментарии