简体   繁体   English

尝试在Web方法中访问querystring值

[英]Trying to access querystring value in web method

I am trying to pass querystring value from one of the gridview item on click to another web page 'Uncoated_wire.aspx.cs', here I want to use that value inside a web method 'GetCustomers' .how to achieve that. 我正在尝试将querystring值从单击的gridview项中传递到另一个网页'Uncoated_wire.aspx.cs',在这里我想在Web方法'GetCustomers'中使用该值。如何实现这一点。 tad.aspx tad.aspx

<script type="text/javascript">
        $(function () {
            $("#THistory").click(function (event) {               
                event.preventDefault();
                $("#pdfFormInsideL1").hide();
                document.getElementById('<%=gvCustomers.ClientID%>').style.display = 'block';
                //$("#gvCustomers").show();
                $("#gvCustomers").attr("visibility", "visible");
                $.ajax({
                    type: "POST",
                    url: "TDC.aspx/GetCustomers",
                    data: '{}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    failure: function (response) {
                        alert(response.d);
                    },
                    error: function (response) {
                        alert(response.d);
                    }
                });
            });
            function OnSuccess(response) {
                var xmlDoc = $.parseXML(response.d);
                var xml = $(xmlDoc);
                var customers = xml.find("Table");
                var row = $("[id*=gvCustomers] tr:last-child").clone(true);
                $("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
                $.each(customers, function () {
                    var customer = $(this);
                    //$("td", row).eq(0).html($(this).find("TDC_NO").text());
                    $("td", row).eq(0).find("a").text($(this).find("TDC_NO").text());
                    ***$("td", row).eq(0).find("a").attr("href", "Uncoated_Wire.aspx?Id=" + $(this).find("TDC_NO").text()).attr('target', '_blank');***                    
                    $("td", row).eq(1).html($(this).find("REVISION").text());
                    $("td", row).eq(2).html($(this).find("REVISION_DATE").text());
                    $("td", row).eq(3).html($(this).find("P_GROUP").text());
                    $("[id*=gvCustomers]").append(row);
                    row = $("[id*=gvCustomers] tr:last-child").clone(true);
                });
            }
        });
        </script>

The highlighted star mark code line is used for passing value to another web page uncoated_wire.aspx.cs 突出显示的星号代码行用于将值传递给另一个网页uncoated_wire.aspx.cs

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;
    }

In this web method I want to access that querystring parameter how to do that.Any idea wouldd be appreciated 在此Web方法中,我想访问该querystring参数的操作方法。

Try this code to get querystring from WebMethod. 尝试使用此代码从WebMethod获取查询字符串。

[WebMethod]
public static string GetCustomers()
{
    string strId = HttpContext.Current.Request.QueryString["Id"];
    //dosomething    
}

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM