如何在静态函数中访问 html 控件 (Asp.net)

how to access html control in static function (Asp.net)

我正在尝试访问我的静态函数的 html 控件,但我遇到了编译时间错误 所以请给我解决方案

这是我的代码

[System.Web.Services.WebMethod]    
public static void btnPostNote_Click(string note)
{
    string borrowerId = Data.QueryString("id");

    note = "";
    RefreshNotes(borrowerId);
    lblNoteSaved.Text = "Note Successfully Saved
}

我尝试了下面的解决方案,所以我得到了空指针异常

[System.Web.Services.WebMethod]
public static void btnPostNote_Click(string note)
{
   if (HttpContext.Current != null)
   {
     Page page = (Page)HttpContext.Current.Handler;
     Label lblNoteSaved = (Label)page.FindControl("lblNoteSaved");
     string borrowerId = Data.QueryString("id");

     note = "";
     RefreshNotes(borrowerId);
     lblNoteSaved.Text = "Note Successfully Saved";                
   }
}

您可以使用 AJAX 和 JQuery 因为这 3 个链接会对您有所帮助

Accessing runat="server" control id in WebMethod

http://www.itorian.com/2012/07/calling-aspnet-c-method-web-method.html