function switchView(objname,current)
{
var obj = $get(objname);
if(obj.style.display=="block" || obj.style.display=="")
{
obj.style.display="none";
current.src ='../App_Themes/images/s_right.gif';
PageMethods.SetToolbarDisplayFlag("none",OnSucceeded,OnFailed);
}
else
{
obj.style.display="block";
current.src ='../App_Themes/images/s_left.gif';
PageMethods.SetToolbarDisplayFlag("block",OnSucceeded,OnFailed);
}
}
function OnSucceeded(result, userContext, methodName)
{
return;
}
function OnFailed(error, userContext, methodName)
{
return;
}
if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
When you click the button, it will cause exception: PageMethods not defined.
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:
public class PageBase : Page
{
[WebMethod]
public static void SetToolbarDisplayFlag(string flag)
{
HttpContext.Current.Session["ToolbarDisplay"] = flag;
}
}
Now, you can invoke methods in MasterPage.