Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在静态函数(Asp.net)中访问html控件_C#_Asp.net_.net_Asmx_Webmethod - Fatal编程技术网

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

C# 如何在静态函数(Asp.net)中访问html控件,c#,asp.net,.net,asmx,webmethod,C#,Asp.net,.net,Asmx,Webmethod,我试图访问静态函数上的html控件,但遇到了复杂时间错误 所以请给我答案 这是我的密码 [System.Web.Services.WebMethod] public static void btnPostNote_Click(string note) { string borrowerId = Data.QueryString("id"); note = ""; RefreshNotes(borrowerId); lblNoteSaved.Text =

我试图访问静态函数上的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个链接将帮助您


您将无法在Web方法中获得控件。Web方法的行为类似于无状态API。在这种情况下,ViewState数据不会回发到服务器。所以答案很简单,您不能。但是,您可以将数据从客户端(浏览器)传递到该WebMethod。因此,我如何做到这一点,请给出使用jquery ajax调用web方法的另一种方法。例如@Rashi Gupta如果对您有帮助,请将其标记为答案