asp.net access a control from static function

后端 未结 2 1794
清酒与你
清酒与你 2020-12-18 13:50

I have a webform and in that webform, I am trying to access a Panel object from a static method, but couldn\'t access it How can I access a Panel object from static method.

2条回答
  •  借酒劲吻你
    2020-12-18 14:15

    public static void DoSomething()
    {
        if (HttpContext.Current != null)
        {
            Page page = (Page)HttpContext.Current.Handler;
            TextBox TextBox1 = (TextBox)page.FindControl("TextBox1");
    
            TextBox TextBox2 = (TextBox)page.FindControl("TextBox2");
        }
    }
    

提交回复
热议问题