Search code examples
c#asp.netjavascriptpagemethods

Using PageMethods to access MultiiView Control ASP.Net


I have a multiview on my ASPX page whose ActiveViewIndex I want to set using JavaScript. For this, I have used UpdatePanel inside which the MultiView control is placed. I have enabled the EnablePageMethods="True" of the ScriptManager.

Whenever I am calling the Server Method I am getting:

Object reference not set to an Instance of an Object

function CallScreens(id) 
{
    // var id,var type
    // Call server side function
    alert('Hello');
    PageMethods.SetScreens("-1","screen",OnCallSumComplete,OnCallSumError,"");
}

The Server Side code is as given below

[System.Web.Services.WebMethod]

public static void SetScreens(string id,string Type)
{
    try
    {
        TreeView obj = new TreeView();//Name of my Class
        obj.MultiView1.ActiveViewIndex=1;
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

Solution

  • Are you getting this error because MultiView1 has not been instantiated in the TreeView object? Also, webmethods don't have access to the page elements because they are treated as static.