Tech Off Thread

7 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Dropdownlist does not cause postback asp.net

Back to Forum: Tech Off
  • User profile image
    lesmemphis

    Hey, I've got a dropdownlist in a asp:gridview , I've set the autopostback to true, but it's still not posting. Why?

     

    <asp:DropDownList ID="Pax"

              runat="server"

              AutoPostBack="True"

              OnSelectedIndexChanged="Pax_SelectedIndexChanged">

    </asp:DropDownList>

     

    In code behind:

    protected void Pax_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedPax = Convert.ToInt32(((DropDownList)sender).SelectedValue);
        }

     

    Now I don't know if it would call the code behind method in the first place, but currently it doesn't cause a postback at all. Why is this?

  • User profile image
    spivonious

    Are there any items in the list? The event won't fire unless the selection can actually be changed.

  • User profile image
    lesmemphis

    spivonious said:

    Are there any items in the list? The event won't fire unless the selection can actually be changed.

    yes, I add the items from ann Asp:table.

     

    you can view an example of the page here:

     

    Postback Issues

  • User profile image
    cheong

    I don't know it they have fixed it, but remember that when I was working on .NET v1.1, both DropDownList and select tag won't work.

     

    I have to implement select tag then explicitly write any <submit button>.click() on onchange event. (Apparently the SelectedIndexChanged event has been queued in the postback metadata, just that postback somehow not triggered. The event handler will run the event on the next postback occurred)

     

    Just remember that you MUST turn off AutoEventWireup in order to use this workaround.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    lesmemphis

    cheong said:

    I don't know it they have fixed it, but remember that when I was working on .NET v1.1, both DropDownList and select tag won't work.

     

    I have to implement select tag then explicitly write any <submit button>.click() on onchange event. (Apparently the SelectedIndexChanged event has been queued in the postback metadata, just that postback somehow not triggered. The event handler will run the event on the next postback occurred)

     

    Just remember that you MUST turn off AutoEventWireup in order to use this workaround.

    I'm not sure I understand your solution. You mean that the event will fire once a postback occurs, but that you have to insert a seperate submit field to invoke the postback?

  • User profile image
    blowdart

    That should be all you need to do, there's no need to jump through manual steps at all. You're not running noscript or anything? Have you examined the DOM to make sure the events are binding? There's nothing setting properties on that control which might turn autopostback off?

     

    Also how are you adding items? You say it's from an asp:table? How? Server side code? During postback? If you're binding on every post back you need to stop that - wrap the binding in an if (!IsPostBack) otherwise the item in the drop down which caused the postback won't exist at the right point

  • User profile image
    cheong

    lesmemphis said:
    cheong said:
    *snip*

    I'm not sure I understand your solution. You mean that the event will fire once a postback occurs, but that you have to insert a seperate submit field to invoke the postback?

    Yes, the bug condition and the workaround I said applies to .NET v1.1 web applications, in quite consistant manner.

     

    I have not verified if this trick is needed in v2.0 or above, so you should try to deduce it yourself.

     

    Just create a new webform with just a dropdownlist in a form tag, and put the server side event for onchange there to see if it works.

     

    If it just works, then possibly some of your origional pages tag got overlapped/not closed so your form is not the parent of the dropdownlist. A simple "javascript: alert(document.getElementById("Pax").parent)" in address bar should help you check for that.

     

    If not, add a submit button and click it after you changed dropdownlist item. If it's noscript problem, your server-side code won't fire even if you "clicked" the submit button. If it's just javascript problem, you should be able to see little yellow triangle on the corner of your browser flagging javascript in your page is broken.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.