0

Can I bind asp.net dropdownlist using javascript/jquery? I get the data from jquery ajax from a web method so I want to avoid postback at this point. But I still want to do postback and save all the data using server side code (i.e. I still be able to do this dropdownlist1.selecteditem.text) after binding it using clientscripts.

Is it possible and can someone explain me how it can be done?

Thanks,

1 Answer 1

0

Use Json ajax

Syntax:

$.ajax({
dataType: "json",
url: url,
data: data,
success: success
});

See simple example for json:

<script type="text/javascript">
        $(document).ready(function () {
            var msgbox = $("#status");
            $("#Button1").click(function () {
                $.ajax({
                    type: "POST",

                    //Page Name (in which the method should be called) and method name
                    url: "BeginJson.aspx/CheckDateTime",
                    // If you want to pass parameter or data to server side function you can try line
                   // data: "{}",
                    //else If you don't want to pass any value to server side function leave the data to blank line below
                    data: "{'args':'Somnath'}",


                    contentType: "application/json; charset=utf-8",

                    dataType: "json",

                    success: function (msg) {
                        //Got the response from server and render to the client
                        msgbox.html(msg.d);
                    }
                });
            });
        });
1
  • I have tried many things and finally gave up the idea to do this. The problem was the event validation failed once an asp.net control has been altered. i.e. I will never be able to use 2 technologies together. I can't rewrite all the server code so I gave up the idea of doing partial ajax. Thanks.
    – Laurence
    May 31, 2013 at 12:58

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.