c# - Pass master page control values on content page on page_load -
i have dropdowlist on master page , want pass selected value on content pages when content page loads. problem value passes when change value on dropdownlist. when page load have reselect dropdownlist capture value of dropdown. if browsing content pages selected value doesnt pass on page load. master page code .net:
<asp:dropdownlist id="ddlcategories" runat="server" datasourceid="sqldatasourcecategories" datatextfield="categoryname" datavaluefield="categoryid" autopostback="true" onselectedindexchanged="ddlcategories_selectedindexchanged"></asp:dropdownlist>
master page cs:
protected void page_load(object sender, eventargs e) { if (!ispostback) { ddlcategories.databind(); ddlcategories.items.insert(0, "uncategorized"); ddlcategories.items[0].value = "0"; ddlcategories.selectedvalue = convert.tostring(session["lblcategoryid"]); } } protected void ddlcategories_selectedindexchanged(object sender, eventargs e) { session["lblcategoryid"] = convert.toint32(ddlcategories.selectedvalue); }
content page cs:
protected void page_load(object sender, eventargs e) { label10.text = convert.tostring(((dropdownlist)master.findcontrol("ddlcategories")).selectedvalue); }
try solution:
master page:
<asp:dropdownlist id="ddlcategories" runat="server" autopostback="true" onselectedindexchanged="ddlcategories_selectedindexchanged"> <asp:listitem>one</asp:listitem> <asp:listitem>two</asp:listitem> </asp:dropdownlist>
master page cs:
public string selectedvalue { { return ddlcategories.selectedvalue; } set { ddlcategories.selectedvalue= value; } } protected void ddlcategories_selectedindexchanged(object sender, eventargs e) { selectedvalue = ddlcategories.selectedvalue; }
content page markup:
<%@ mastertype virtualpath="~/site1.master" %> <asp:label id="label1" runat="server" text="label"></asp:label>
content page cs.
protected void page_prerender(object sender, eventargs e) { label1.text = master.selectedvalue; }
note: values demonstrate, can use actual data source values in drop down.
Comments
Post a Comment