How to execute event code for DropDownList?

Discussion in 'ASP .Net Web Controls' started by Waldy, May 8, 2008.

  1. Waldy

    Waldy Guest

    Hi there,
    when you double click a drop down control on a web form, it
    creates the OnSelectedIndexChanged function placeholder in the code behind
    file. How do you then get that code to execute? Changing the selection of
    the drop down does not return to the server even though I have the
    runat=server tags on the controls. A button on the same page does run the
    OnClick event code in when you click it. I tried setting the AutoPostback
    setting to true, and then the page gets re-loaded, but it still does not
    execute the attached event code.

    What am I missing?
    Waldy, May 8, 2008
    #1
    1. Advertising

  2. Hello Waldy

    > when you double click a drop down control on a web form, it
    > creates the OnSelectedIndexChanged function placeholder in the code behind
    > file. How do you then get that code to execute? Changing the selection
    > of the drop down does not return to the server even though I have the
    > runat=server tags on the controls. A button on the same page does run the
    > OnClick event code in when you click it. I tried setting the AutoPostback
    > setting to true, and then the page gets re-loaded, but it still does not
    > execute the attached event code.

    The only thing you need is to set AutoPostBack of the Control to "true".
    You said, that its not working after that..... so let us see your Code,
    to explore the issue...

    --
    Gruss, Peter Bucher
    Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
    Peter Bucher [MVP], May 8, 2008
    #2
    1. Advertising

  3. Waldy

    Waldy Guest

    Hi there,

    "Peter Bucher [MVP]" <> wrote in message
    news:...
    >so let us see your Code,


    It's not easy as it is a large project. I created a new page to demonstrate
    the problem and it works as expected on that page. What determines whether
    or not event code is executed at the server? The output of the problem page
    and the new page looks exactly the same as far as the dropdown is concerned.
    The only javascript is calling the __doPostback method.
    Waldy, May 8, 2008
    #3
  4. Hi Waldy

    > It's not easy as it is a large project. I created a new page to
    > demonstrate the problem and it works as expected on that page.

    ok

    > What determines whether or not event code is executed at the server? The
    > output of the problem page and the new page looks exactly the same as far
    > as the dropdown is concerned. The only javascript is calling the
    > __doPostback method.

    This can vary by different things.
    In the included ASP.NET Components is that mainly a Javascript caused
    postback with some Parameters that match the ones where on the Server
    expected.

    Its now difficult to say whats the problem in your issue.
    Please show the two similar small Parts of the output...
    .... maybe theres a difference to catch.

    --
    Gruss, Peter Bucher
    Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET
    Peter Bucher [MVP], May 9, 2008
    #4
  5. Waldy

    Stan Guest

    On 8 May, 15:34, "Waldy" <> wrote:
    > Hi there,
    >
    > "Peter Bucher [MVP]" <> wrote in messagenews:...
    >
    > >so let us see your Code,

    >
    > It's not easy as it is a large project.  I created a new page to demonstrate
    > the problem and it works as expected on that page.  What determines whether
    > or not event code is executed at the server?  The output of the problem page
    > and the new page looks exactly the same as far as the dropdown is concerned.
    > The only javascript is calling the __doPostback method.


    Are you sure that the dropdown control is failing to postback?

    If you are using Visual Studio and can run the project in debug mode,
    one way to check this is to put a line or two of passive code in the
    page_load event that executes when IsPostback is true. Then put a
    debug break there. Run the page and click the dropdownlist. If it's
    posting back then debug will halt it for you to see.

    A much more common problem is the designated event code handler not
    being executed on postback. This can happen after extensive editing
    where event handling routines are liable to become orphaned. For
    example if you place a control on the page, use the click method to
    autogenerate an event "placeholder" then delete the control and put
    back later leads to a situation where the original event code will not
    be "wired up" to anything and the compiler just ignores it.

    HTH
    Stan, May 12, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernie V
    Replies:
    3
    Views:
    28,934
    Bernie V
    Nov 29, 2003
  2. =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=

    Fire Code behind code AND Javascript code associated to a Button Click Event

    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Feb 10, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    21,209
    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=
    Feb 11, 2004
  3. Kamal Ahmed
    Replies:
    1
    Views:
    5,206
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
    Oct 25, 2005
  4. Replies:
    1
    Views:
    439
    Craig Deelsnyder
    Mar 31, 2006
  5. Savas Ates
    Replies:
    1
    Views:
    276
    Patrice
    Aug 17, 2004
Loading...

Share This Page