How to invoke PageMethods in MasterPage
<div id="left" style='<%=string.Format("display:{0}",GetToolbarDisplayFlag())%>'>
</div>
</div>
Remember to set the EnablePageMethods = "True"
return HttpContext.Current.Session["ToolbarDisplay"] == null ? "block" : HttpContext.Current.Session["ToolbarDisplay"].ToString(); } }
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
This is because the method "SetToolbarDisplayFlag" Js invoke is in MasterPage, it seems PageMethods donot contain MasterPage methods. So, my solution is move the method "SetToolbarDisplayFlag" from MasterPage to a base page called "PageBase" which inherited from System.Web.UI.Page, and each WebContentPage derived from PageBase. PageBase.cs: { } }
JS:
When you click the button, it will cause exception: PageMethods not defined.
public class PageBase : Page
Now, you can invoke methods in MasterPage.