Jquery autopostback dropdown selector

In jQuery, there is some way to distinguish drop-down lists and postback relaying (ASP.NET 3.5):

$('select').change(function(e) { //something like this if ($(this).attr('AutoPostback') == true) { //do something here } else { //do something else } 

Think about whether to reference the server-side function from the script here to determine AutoPostback.

+7
jquery
source share
3 answers

Typically, a drop-down list that will be sent back will have an onchange attribute that contains something like "__doPostBack" ("although there will also be some other things.

So you can do something like below that I have not tested, so hopefully there are no typos

 $('select[onchange*="__doPostBack("]').change(...your handler for postbacking control...); $('select:not([onchange*="__doPostBack("])').change(...your handler for non-postbacking control...); 
+4
source share

The AutoPostBack attribute, IIRC, is server-side. In other words, it is parsed by the server and never makes it in the browser.

This will be a bit redundant in code, but you can give it cssclass = "AutoPostback" and then check it through jQuery

0
source share

I came across this topic a bit, but maybe someone else along the way will find this useful.

I was also having trouble getting jquery ui selectmenu to do the postback. previous comments got me pretty close, but errors occurred when I started it. This may be due to the version I'm using, but my final solution was to attach the postback to the change event a little differently. I had to pass strings instead of a callback instead of the actual element. The first parameter is the identifier of the select element, and the second parameter is the name of the function being called on the server side.

 $("#cboStateFilter").selectmenu({ change: function (event, ui) { __doPostBack("cboStateFilter", 'cboStateFilter_SelectedIndexChanged'); } }); 
0
source share

All Articles