Student Reviews
( 5 Of 5 )
1 review
Video of Loading controls dynamically in asp.net Part 110 in ASP.net course by kudvenkat channel, video No. 110 free certified online
Text version of the video
http://csharp-video-tutorials.blogspot.com/2013/01/loading-controls-dynamically-in-aspnet.html
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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation1
Slides
http://csharp-video-tutorials.blogspot.com/2013/08/part-110-loading-aspnet-controls.html
All ASP .NET Text Articles
http://csharp-video-tutorials.blogspot.com/p/free-aspnet-video-tutorial.html
All ASP .NET Slides
http://csharp-video-tutorials.blogspot.com/p/aspnet-slides.html
All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view1&sortdd
All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists
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
http://csharp-video-tutorials.blogspot.com/2013/01/loading-controls-dynamically-in-aspnet.html
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);
}
}