0

This code below sitting on a ASP.Net application on the Site.Mater....

I need to pass another two parameters from the default.aspx page, one asp:label and one asp:textbox

What is the easiest way to do that?

Thanks

     <script type="text/javascript">
        $(function () {
                $(".tb").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "TestWebService.asmx/FetchList",
                        data: "{ 'testName': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function (data) { return data; },
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    value: item.Name

                                }
                            }))
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
                        }
                    });
                },
                minLength: 2

            });
        });

1 Answer 1

2

In your jQuery autocomplete, You need to change your data parameter to this:

data: "{ 'testName': '" + request.term + "' ,lbl: '" + $(".lblClass").text() + "' ,txt: '" + $(".txtClass").val() + "'}"

And then change your service method like this:

[WebMethod]
public List<string> FetchList(string testName, string lbl, string txt)
{
  //...
}


Note: .lblClass and .txtClass are classes for ASP:Lable and ASP:TextBox respectively.

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

12 Comments

Thank you, this is great... but how do you know which textbox or label to pass? (I have several textboxes and labels in the default.aspx page)
The easiest way is to assign "class" name to them.
Could you please tell me how to do that?
I also get an error when using this data: "{ 'testName': '" + request.term + "' ,lbl: '" + $(".lblClass").text() + "' ,txt:
Do like this: <asp:textbox class="txtClass" runat="server"/>...same for the label...
|

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.