当ajax调用时,以静态方法访问页面控件

时间:2012-12-07 05:18:50

标签: jquery asp.net ajax static findcontrol

我通过jquery调用我的服务器端方法,并且从该方法我尝试访问页面控制但是给出了错误。这是我的示例代码

    [WebMethod]
    public static findEvents(string PID)
    {
        Page page = HttpContext.Current.Handler as Page;
        Panel pn=(Panel)page.FindControl("hdContainer");
    }

but find control gives null error. please give any solution to find control in static method.

1 个答案:

答案 0 :(得分:0)

我搜索过这样的内容。

静态方法无法引用实例引用。您需要从类中的其他实例方法传入对HttpContext或页面本身的引用。我认为您需要使用如下参数调用静态Web服务:

[WebMethod]
public static findEvents(string PID, System.Web.UI.Page page)
{        
    Panel pn=(Panel)page.FindControl("hdContainer");
}

它可能对你有帮助。