0

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. 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

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

7
  • you grab the the value from the request, just like you would in a page. Commented Jan 18, 2018 at 4:49
  • @mason how can u show .I have tried but getting errror. Commented Jan 18, 2018 at 4:57
  • You haven't shown your attempt or explained what error you're getting. That information belongs in your question. Commented Jan 18, 2018 at 4:58
  • @mason i have edit the question .how i am trying to get value in web method using hidden field .But getting error an object refrence is required for non-static field..What would be the best approach. Commented Jan 18, 2018 at 5:05
  • 1
    Possible duplicate of Cannot retrieve a querystring parameter. Commented Jan 18, 2018 at 5:16

1 Answer 1

2

Try this code to get querystring from WebMethod.

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

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.