简体   繁体   中英

Can I bind asp.net dropdownlist using javascript/jquery?

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 (ie 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,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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