I 've a master page with an scriptmanager with EnablePAgeMethods=true.
I want to call from that page a static methode from my page within client side with a call like PageMethods.DeleteFIle()-this beeing a javascript proxy class which supoused to be generated by the script manager.
The issue is that this call work well from a simple page but not from master page -on java script i 've got the PageMaster it's unknown.
Thank you
Hi,
Here is a sample made according to your requirement. Please try it:
[Master page]
<%@. Master Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title> </head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager> <input id="Button1" type="button" value="button" onclick="SayHello();"/> <input id="Text1" type="text" /> <asp:contentplaceholder id="ContentPlaceHolder1" runat="server"> </asp:contentplaceholder> </div> <script type="text/javascript"> function SayHello() { PageMethods.Hello(onComplete); } function onComplete(result) { $get("Text1").value = result; } </script> </form></body></html>
[Content page]
<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %><script runat="server"> protected void Page_Load(object sender, EventArgs e) { } [System.Web.Services.WebMethod] public static string Hello() { return "Hello world!"; }</script><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></asp:Content>
Hope this helps.
I have nearly this exact scenario, but the result returned is always the complete markup for the page. Any ideas as to why this is?
Can you show me your code
I also have the same problem. The pagemethod callback shows full page markup instead of return value.
Here's the code
<%-- <Snippet1 Master page> --%>
<%@.MasterCodeFile="MasterPage.master.cs"Inherits="MasterPage"Language="C#" %>
<%@.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI"TagPrefix="asp" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headid="Head1"runat="server">
<title>UpdatePanel in Master Pages</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<pstyle="font-family: Playbill, Fantasy; background-color: olive; font-weight: bold;
font-size: xx-large;">
Master Page
</p>
<hr/>
<asp:ScriptManagerID="ScriptManager1"runat="server"EnablePageMethods="true">
</asp:ScriptManager>
<hr/>
<br/>
<asp:ContentPlaceHolderID="ContentPlaceHolder1"runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
<%-- </Snippet1> --%>
<%-- <Snippent2 Child content page> --%>
<%@.PageCodeFile="Child.aspx.cs"Inherits="Child"Language="C#"MasterPageFile="MasterPage.master"
Title="UpdatePanel in Master Pages" %>
<%@.RegisterAssembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI"TagPrefix="asp" %>
<asp:ContentID="Content1"runat="Server"ContentPlaceHolderID="ContentPlaceHolder1">
<pstyle="font-family: Playbill, Fantasy; background-color: aqua; font-weight: bold; font-size: xx-large;"> Content Page</p>
<hr/>
<scripttype="text/javascript">
function doload()
{
PageMethods.GetName(GetName_Complete);
}
function GetName_Complete()
{
if(arguments.length >0)
{
alert(arguments[0].toString());
//document.getElementById('<%=txt1.ClientID %>').value = arguments[0].toString();
}
}
</script>
<asp:TextBoxID="txt1"runat="server"></asp:TextBox>
<inputid="Button2"onclick="doload()"type="button"value="button"/><br/>
<br/>
<asp:UpdatePanelid="UpdatePanel2"runat="server">
<contenttemplate>
<asp:TextBoxid="txtChild"runat="server"></asp:TextBox>
</contenttemplate>
<triggers>
<asp:AsyncPostBackTriggerControlID="lnkChild"EventName="Click"></asp:AsyncPostBackTrigger>
</triggers>
</asp:UpdatePanel>
<asp:ButtonID="lnkChild"runat="server"OnClick="lnkChild_Click"Text="Ajax Update"/>
<hr/>
</asp:Content>