tags:

views:

153

answers:

2

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 here  

        } 
       else  
        { 
          //do something else 
        }  

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

A: 

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

DA
Thanks for reply. Yeah, I know it's a server side that's why I said I probably have to call a server-side function here from selector
Victor
Well, come to think of it, most controls set to do auto-postback are doing so via javascript, so perhaps there's a way to check for that.
DA
Yes, turns out there is, see reply above
Victor
+3  A: 

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...);
jarrett
There is a typo, but if you do 'select[onchange*="__doPostBack"]' then it's all great, thanks so much.
Victor