C# 尝试访问web方法中的querystring值
我试图将查询字符串值从单击时的一个gridview项传递到另一个网页“Uncoated_wire.aspx.cs”,这里我想在一个web方法“GetCustomers”中使用该值。如何实现这一点。 tad.aspxC# 尝试访问web方法中的querystring值,c#,asp.net,webmethod,C#,Asp.net,Webmethod,我试图将查询字符串值从单击时的一个gridview项传递到另一个网页“Uncoated_wire.aspx.cs”,这里我想在一个web方法“GetCustomers”中使用该值。如何实现这一点。 tad.aspx 在这个web方法中,我想访问这个querystring参数,如何访问它。如果您有任何想法,我将不胜感激。请尝试下面的代码,从WebMethod获取querystring [WebMethod] public static string GetCustomers() { str
在这个web方法中,我想访问这个querystring参数,如何访问它。如果您有任何想法,我将不胜感激。请尝试下面的代码,从WebMethod获取querystring
[WebMethod]
public static string GetCustomers()
{
string strId = HttpContext.Current.Request.QueryString["Id"];
//dosomething
}
希望这有帮助 您从请求中获取值,就像在页面中一样。@mason您如何显示。我已经尝试过,但出现了错误。您没有显示您的尝试,也没有解释您遇到了什么错误。该信息属于您的问题。@mason我已编辑了该问题。我如何尝试使用隐藏字段在web方法中获取值。但获取错误非静态字段需要对象引用。最佳方法是什么。可能重复
protected void Page_Load(object sender, EventArgs e)
{
string TDC_NO_VAL = Request.QueryString["Id"];
hdn_val.Value = TDC_NO_VAL;
}
[WebMethod]
public static string GetCustomers()
{
hdn_val.Value = TDC_NO_VAL;
}
[WebMethod]
public static string GetCustomers()
{
string strId = HttpContext.Current.Request.QueryString["Id"];
//dosomething
}