I have code that is working on good, but when i moved it to MasterPage/ContentPage design it's not functioning as expected. I have no error messages. The code without MasterPage/ContentPage:
//aspx:
<ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true"
ID="ScriptManager1" AsyncPostBackTimeout="90" EnablePageMethods="True"
onasyncpostbackerror="ScriptManager1_AsyncPostBackError" >
</ajaxToolkit:ToolkitScriptManager>
<asp:UpdatePanel runat="server" ID="up2" OnLoad="up2_Load">
<ContentTemplate>
<asp:Panel ID="pnlLiterals" runat="server">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="updPanel" runat="server">
<ContentTemplate>
<asp:Button ID="btn1" runat="server" Text="Update" OnClick="btn1_Click" />
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
//codebehind
protected void btn1_Click(object sender, EventArgs e)
{
//do some stuff..
ScriptManager.RegisterClientScriptBlock(updPanel, updPanel.GetType(), "update", "__doPostBack('up2', '');", true);
}
protected void up2_Load(object sender, EventArgs e)
{
if (ScriptManager1.IsInAsyncPostBack == true && ScriptManager1.AsyncPostBackSourceElementID == "up2")
{
//want to get here.
//If everything is on 1 page it works. If I have btn1 on MasterPage and the rest on ContentPage it doesn't work
//it returns ScriptManager1.IsInAsyncPostBack == false, ScriptManager1.AsyncPostBackSourceElementID ==""
}
}
The difference is that the button (btn1) is on the MasterPage and everything else is in the ContentPage. The code how it looks on MasterPage/ContentPage:
//MasterPage.aspx:
<ajaxToolkit:ToolkitScriptManager runat="Server" EnablePageMethods="True" EnablePartialRendering="true"
EnableScriptGlobalization="true" EnableScriptLocalization="true" ID="ScriptManager1"
onasyncpostbackerror="ScriptManager1_AsyncPostBackError">
<Services>
<asp:ServiceReference Path="AutoComplete.asmx" />
</Services>
</ajaxToolkit:ToolkitScriptManager>
<asp:UpdatePanel ID="updatePanel2" runat="server">
<ContentTemplate>
<asp:Button ID="btn1" runat="server" Text="Update" OnClick="btn1_Click" />
//..other stuff
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="txtCity1" EventName="TextChanged" />
<asp:AsyncPostBackTrigger ControlID="txtCity2" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
//ContentPage.aspx:
<asp:ScriptManagerProxy runat="Server" ID="ScriptManager2" />
<asp:UpdatePanel runat="server" ID="up2" OnLoad="up2_Load">
<ContentTemplate>
<asp:Panel ID="pnlLiterals" runat="server">
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</asp:Panel>
<asp:Label ID="lblGuid" runat="server" Text="Label" />
</ContentTemplate>
</asp:UpdatePanel>
//codebehind ContentPage.aspx.cs
protected void btn1_Click(object sender, EventArgs e)
{
//do some stuff..
ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")),
((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('up2', '');", true);
}
protected void up2_Load(object sender, EventArgs e)
{
if (((ToolkitScriptManager)Page.Master.FindControl("ScriptManager1")).IsInAsyncPostBack == true &&
((ToolkitScriptManager)Page.Master.FindControl("ScriptManager1")).AsyncPostBackSourceElementID == "up2")
{
//want to get here.
//If everything is on 1 page it works. If I have btn1 on MasterPage and the rest on ContentPage it doesn't work
//is returns ScriptManager1.IsInAsyncPostBack == false, ScriptManager1.AsyncPostBackSourceElementID ==
""
}
}
//codebehind MasterPage.aspx.cs
//nothing special
How to call up2_Load event with ScriptManager.RegisterClientScriptBlock when having this design with MasterPage/ContentPage?
When in MasterPage, the DOM id rendered may be different, so, in the __doPostBack function, you'll need to check if 'up2' is correct. You may view source page, to find what ID is rendered in this context.
That's right, this is the problem. I've found the IDs which i needed and solve the problem.
But there's a strange thing, in my localhost IIS server and ASP.NET Development Server (Visual Studio debugging) the MasterPage/ContentPage ids are different:
//OK for IIS localhost
ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('ContentPlaceHolder1_Tabs_TabPanel1_up2', '');", true);
//OK for ASP.NET Development Server
ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('ctl00_ContentPlaceHolder1_Tabs_TabPanel1_up2', '');", true);
Why is that, do you have any explanation about it?
Digitborn.co...
Member
684 Points
450 Posts
MasterPage/ContentPage, UpdatePanel and ScriptManager.RegisterClientScriptBlock
Apr 04, 2012 03:48 PM|LINK
Hello,
I have code that is working on good, but when i moved it to MasterPage/ContentPage design it's not functioning as expected. I have no error messages. The code without MasterPage/ContentPage:
//aspx: <ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ScriptManager1" AsyncPostBackTimeout="90" EnablePageMethods="True" onasyncpostbackerror="ScriptManager1_AsyncPostBackError" > </ajaxToolkit:ToolkitScriptManager> <asp:UpdatePanel runat="server" ID="up2" OnLoad="up2_Load"> <ContentTemplate> <asp:Panel ID="pnlLiterals" runat="server"> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </asp:Panel> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="updPanel" runat="server"> <ContentTemplate> <asp:Button ID="btn1" runat="server" Text="Update" OnClick="btn1_Click" /> </ContentTemplate> <Triggers> </Triggers> </asp:UpdatePanel> //codebehind protected void btn1_Click(object sender, EventArgs e) { //do some stuff.. ScriptManager.RegisterClientScriptBlock(updPanel, updPanel.GetType(), "update", "__doPostBack('up2', '');", true); } protected void up2_Load(object sender, EventArgs e) { if (ScriptManager1.IsInAsyncPostBack == true && ScriptManager1.AsyncPostBackSourceElementID == "up2") { //want to get here. //If everything is on 1 page it works. If I have btn1 on MasterPage and the rest on ContentPage it doesn't work //it returns ScriptManager1.IsInAsyncPostBack == false, ScriptManager1.AsyncPostBackSourceElementID =="" } }The difference is that the button (btn1) is on the MasterPage and everything else is in the ContentPage. The code how it looks on MasterPage/ContentPage:
//MasterPage.aspx: <ajaxToolkit:ToolkitScriptManager runat="Server" EnablePageMethods="True" EnablePartialRendering="true" EnableScriptGlobalization="true" EnableScriptLocalization="true" ID="ScriptManager1" onasyncpostbackerror="ScriptManager1_AsyncPostBackError"> <Services> <asp:ServiceReference Path="AutoComplete.asmx" /> </Services> </ajaxToolkit:ToolkitScriptManager> <asp:UpdatePanel ID="updatePanel2" runat="server"> <ContentTemplate> <asp:Button ID="btn1" runat="server" Text="Update" OnClick="btn1_Click" /> //..other stuff </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="txtCity1" EventName="TextChanged" /> <asp:AsyncPostBackTrigger ControlID="txtCity2" EventName="TextChanged" /> </Triggers> </asp:UpdatePanel> //ContentPage.aspx: <asp:ScriptManagerProxy runat="Server" ID="ScriptManager2" /> <asp:UpdatePanel runat="server" ID="up2" OnLoad="up2_Load"> <ContentTemplate> <asp:Panel ID="pnlLiterals" runat="server"> <asp:Literal ID="Literal1" runat="server"></asp:Literal> </asp:Panel> <asp:Label ID="lblGuid" runat="server" Text="Label" /> </ContentTemplate> </asp:UpdatePanel> //codebehind ContentPage.aspx.cs protected void btn1_Click(object sender, EventArgs e) { //do some stuff.. ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('up2', '');", true); } protected void up2_Load(object sender, EventArgs e) { if (((ToolkitScriptManager)Page.Master.FindControl("ScriptManager1")).IsInAsyncPostBack == true && ((ToolkitScriptManager)Page.Master.FindControl("ScriptManager1")).AsyncPostBackSourceElementID == "up2") { //want to get here. //If everything is on 1 page it works. If I have btn1 on MasterPage and the rest on ContentPage it doesn't work //is returns ScriptManager1.IsInAsyncPostBack == false, ScriptManager1.AsyncPostBackSourceElementID == "" } } //codebehind MasterPage.aspx.cs //nothing specialHow to call up2_Load event with ScriptManager.RegisterClientScriptBlock when having this design with MasterPage/ContentPage?
BU XI - MSFT
All-Star
22367 Points
2704 Posts
Microsoft
Re: MasterPage/ContentPage, UpdatePanel and ScriptManager.RegisterClientScriptBlock
Apr 06, 2012 03:28 AM|LINK
Hello
When in MasterPage, the DOM id rendered may be different, so, in the __doPostBack function, you'll need to check if 'up2' is correct. You may view source page, to find what ID is rendered in this context.
For your reference,
http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientid.aspx
http://stackoverflow.com/questions/3785483/control-id-change-automatically-in-masterpage
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework
Digitborn.co...
Member
684 Points
450 Posts
Re: MasterPage/ContentPage, UpdatePanel and ScriptManager.RegisterClientScriptBlock
Apr 06, 2012 02:18 PM|LINK
That's right, this is the problem. I've found the IDs which i needed and solve the problem.
But there's a strange thing, in my localhost IIS server and ASP.NET Development Server (Visual Studio debugging) the MasterPage/ContentPage ids are different:
//OK for IIS localhost ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('ContentPlaceHolder1_Tabs_TabPanel1_up2', '');", true); //OK for ASP.NET Development Server ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('ctl00_ContentPlaceHolder1_Tabs_TabPanel1_up2', '');", true);Why is that, do you have any explanation about it?
Do you know how to write it:
if (ASP.Development.Server)
ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('ContentPlaceHolder1_Tabs_TabPanel1_up2', '');", true);
else if (IIS.Server)
ScriptManager.RegisterClientScriptBlock(((UpdatePanel)Master.FindControl("updatePanel2")), ((UpdatePanel)Master.FindControl("updatePanel2")).GetType(), "update", "__doPostBack('ctl00_ContentPlaceHolder1_Tabs_TabPanel1_up2', '');", true);
Digitborn.co...
Member
684 Points
450 Posts
Re: MasterPage/ContentPage, UpdatePanel and ScriptManager.RegisterClientScriptBlock
Apr 06, 2012 07:48 PM|LINK
Further investigation and testing showed up that the ClientID is different for the same control:
on: XP, IIS 5.1 it's 'ContentPlaceHolder1_Tabs_TabPanel1_up2'
on: Server 2008, IIS 7 it's 'ctl00_ContentPlaceHolder1_Tabs_TabPanel1_up2'
on: ASP.NET Development Server it's 'ctl00_ContentPlaceHolder1_Tabs_TabPanel1_up2'