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

            });
        });
D_D
  • 1,019
  • 4
  • 15
  • 25

1 Answers1

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.

yaka
  • 914
  • 1
  • 9
  • 16
  • 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) – D_D Dec 14 '11 at 11:48
  • The easiest way is to assign "class" name to them. – yaka Dec 14 '11 at 11:49
  • Could you please tell me how to do that? – D_D Dec 14 '11 at 11:58
  • I also get an error when using this data: "{ 'testName': '" + request.term + "' ,lbl: '" + $(".lblClass").text() + "' ,txt: – D_D Dec 14 '11 at 11:59
  • Do like this: ...same for the label... – yaka Dec 14 '11 at 12:01
  • For error: (1) did you change your service method? (2) just pass the right data from jquery selectors i mentioned above - maybe that's the cause (3) what error do you get if it still persists? – yaka Dec 14 '11 at 12:04
  • I saw something missing in your comment. Just to double check: Did you use: data: "{ 'testName': '" + request.term + "' ,lbl: '" + $(".lblClass").text() + "' ,txt: '" + $(".txtClass").val() + "'}"....right? – yaka Dec 14 '11 at 12:08
  • Thank you I will check that... I also realised it is not a label what I need to pass but a datepicker which I have created in a class... so the element is something like – D_D Dec 14 '11 at 12:25
  • And Yes, I did not put everything in the comment but I put the whole thing... when I execute it, I just get a message box with "error" – D_D Dec 14 '11 at 12:27
  • I guess (id="datePicker") is what you have in server-side, you need to check the client side equivalent of this dtpicker:Datepicker element. In your class and at the control generation phase, see if you can assign a custom attribute and call it "class" to make sure you can easily access it in jquery by its class name. However, if you know its client ID you can access it by like $("#datepickerClientID") – yaka Dec 14 '11 at 12:59
  • Thank you for all the info, it is starting to look better. One last question... for textbox you use val(), for labels text(), I thought for a checkbox would be Checked... but that does not seem to work – D_D Dec 14 '11 at 13:56
  • try this: http://stackoverflow.com/questions/901712/check-checkbox-checked-property-using-jquery – yaka Dec 14 '11 at 16:32