I have a DropDownList in Masterpage that I fill on Page_Load() event but when child page loads , this DropDownList is binding again because its in Page_Load() event and selected value in this list is lost. Is there any way I can avoid this repeated binding in Masterpage?
I’m passing the selected value from DropDownList through QueryString and showing items according that value in child page.
I’m writing code in C# in ASP.Net using visual studio 2011.
if (!IsPostBack)
{
ViewState["id"] = null;
if (drpdwnCategory.Items.Count < 1)
{
fillDropList();
}
}
if (Request.QueryString["catId"] != null)
{
drpdwnCategory.SelectedIndex = _drpdwnCategory.Items.IndexOf(drpdwnCategory.Items.FindByValue(enrpt.getdecrept(Request.QueryString["catId"])));
}
You still have to bind the dropdown on page load of the child pages, otherwise your dropdown would not have any values inside.
What you can do is to check for the querystring on your masterpage, and then set the SelectedValue property of the dropdown to whatever is in the querystring during your dropdown databind.