I want to change div style (display) in master page from my child page.
I use :
protected void ShowMsgText(int MsgID)
{
HtmlGenericControl MsgInner;
MsgInner =((HtmlGenericControl)Master.FindControl("MsgInner"));
MsgInner.Attributes["class"] = "MsgInnerShow";
}
MsgInner is my div id, But any change after run this !
I have investigated the problem. I believe you have update panel in child page (aspx) and message div in master page. Update panel can update the controls which lie under it but it could not update control those are out side update panel. So you need to put update panel in master page.
In Master Page
<ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ScriptManager1" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div><strong>Demo for master page updation</strong></div>
<div id="divMaster" runat="server">
I am div in master page, going to change with ajax call
</div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</ContentTemplate>
</asp:UpdatePanel>
In content page (.aspx)
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
In content page code behind (.aspx.cs)
protected void Button1_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(2000); //To check the effect of ajax call, must be removed
HtmlGenericControl divMaster = (HtmlGenericControl) this.Master.FindControl("divMaster");
divMaster.InnerHtml = "hello I am being change from child page";
}