开发者

jquery dropdown selector AutoPostback

In jQuery is there any way to distinguish between postbacking dropdowns and non-postbacking ones(ASP.NET 3.5):

$('select').change(function(e)
{
        //something like this
        if ($(this).attr('AutoPostback') == true) 
        { 
           //do something h开发者_运维技巧ere  

        } 
       else  
        { 
          //do something else 
        }  

Think have to call server side function from script here to determine AutoPostback.


Typically, a dropdown that is going to postback will have an onchange attribute that contains something like "__doPostBack(" though there will also be some other stuff in there.

So you could do something like the below, which I didn't test so hopefully there is no typos

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


The AutoPostBack attribute, IIRC, is server-side. In otherwords, it's parsed by the server and never actually makes it to the browser.

It'd be a bit redundant code-wise, but you could give it a cssClass="AutoPostback" and then check for that via jQuery


I came upon this thread a little late but perhaps someone else along the way will find this useful.

I also was having issues getting the jquery ui selectmenu to do a postback. the previous comments got me pretty close but errors came up when i ran it. This may be due to the different version i am using but my final fix was to attach the postback to the change event a little differently. I had to pass strings to the postback call instead of the actual element. First parameter is the ID of the select element and the second perameter is the name of the server side function that is supposed be called.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜