My DropDownList handler isn't executing.

Discussion in 'ASP .Net' started by darrel, Aug 26, 2005.

  1. darrel

    darrel Guest

    I have a asp:dropdownlist set to autopostback.

    However, my handler doesn't seem to execute (even though there is a
    postback).

    Here's the DDL:

    <asp:dropdownlist id=ddl_districtSelect runat="server" AutoPostBack="True">
    (list items)
    </asp:dropdownlist>

    and the handler:

    Private Sub ddl_districtSelect_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    ddl_districtSelect.SelectedIndexChanged
    response.Write("MONKEY")
    End Sub

    Any reason why this wouldn't be executing?

    -Darrel
     
    darrel, Aug 26, 2005
    #1
    1. Advertising

  2. darrel

    darrel Guest

    > However, my handler doesn't seem to execute (even though there is a
    > postback).


    Hmm...I also have another problem. The auto-postback isn't retaining the
    selected value. It keeps reverting to the first item.

    I don't normally use drop down auto-postbacks, so am I just completely not
    'getting' some fundamental concept here?

    -Darrel
     
    darrel, Aug 26, 2005
    #2
    1. Advertising

  3. darrel

    Marina Guest

    Are you rebinding the data every time the page loads? This may be your
    problem. You only need to bind once.

    "darrel" <> wrote in message
    news:%...
    >> However, my handler doesn't seem to execute (even though there is a
    >> postback).

    >
    > Hmm...I also have another problem. The auto-postback isn't retaining the
    > selected value. It keeps reverting to the first item.
    >
    > I don't normally use drop down auto-postbacks, so am I just completely not
    > 'getting' some fundamental concept here?
    >
    > -Darrel
    >
    >
     
    Marina, Aug 26, 2005
    #3
  4. darrel

    darrel Guest


    > Are you rebinding the data every time the page loads? This may be your
    > problem. You only need to bind once.


    Nope. no databinding at all. Just a simple option list right in the HTML
    itself.

    -Darrel
     
    darrel, Aug 26, 2005
    #4
  5. darrel

    Marina Guest

    Do they all have unique values?

    "darrel" <> wrote in message
    news:...
    >
    >> Are you rebinding the data every time the page loads? This may be your
    >> problem. You only need to bind once.

    >
    > Nope. no databinding at all. Just a simple option list right in the HTML
    > itself.
    >
    > -Darrel
    >
    >
     
    Marina, Aug 26, 2005
    #5
  6. darrel

    John Horst Guest

    If your ddl is reverting to the first item and not keeping the selected
    item from prior to the postback, you are probably calling databind() on
    the control on the postback. Here is a general rule of thumb for
    getting data, binding to it and the Page_Load event:

    In page load, before checking the IsPostBack property, get your data.
    Then check if the page is being posted back. If not, call DataBind on
    the controls.

    Page_Load(<<args>>)
    {
    // get data.
    dataAdapter.Fill(dataTable);

    // check for postback.
    if (!this.IsPostBack)
    {
    control.DataBind();
    }
    }

    The exception to this would be if you are using a datareader for your
    ddl. Then get the datareader and bind the control only if the page is
    NOT a postback.

    Page_Load(<<args>>)
    {

    // check for postback.
    if (!this.IsPostBack)
    {
    // get data reader.
    SqlDataReader dr = someCommand.ExecuteReader();
    control.DataSource = dr;
    control.DataTextField = "SomeTextField";
    control.DataValueField = "SomeValueField";
    control.DataBind();
    }
    }

    John


    -----Original Message-----
    From: darrel [mailto:]
    Posted At: Friday, August 26, 2005 1:02 PM
    Posted To: microsoft.public.dotnet.framework.aspnet
    Conversation: My DropDownList handler isn't executing.
    Subject: Re: My DropDownList handler isn't executing.


    > However, my handler doesn't seem to execute (even though there is a
    > postback).


    Hmm...I also have another problem. The auto-postback isn't retaining the
    selected value. It keeps reverting to the first item.

    I don't normally use drop down auto-postbacks, so am I just completely
    not 'getting' some fundamental concept here?

    -Darrel
     
    John Horst, Aug 26, 2005
    #6
  7. darrel

    darrel Guest

    > Do they all have unique values?

    Yes. Here's the full markup:

    <asp:dropdownlist id=ddl_districtSelect runat="server" AutoPostBack="True">
    <asp:ListItem Value="first">1st District</asp:ListItem>
    <asp:ListItem Value="second">2nd District</asp:ListItem>
    <asp:ListItem Value="third">3rd District</asp:ListItem>
    <asp:ListItem Value="fourth">4th District</asp:ListItem>
    <asp:ListItem Value="fifth">5th District</asp:ListItem>
    <asp:ListItem Value="sixth">6th District</asp:ListItem>
    <asp:ListItem Value="seventh">7th District</asp:ListItem>
    <asp:ListItem Value="eigth">8th District</asp:ListItem>
    <asp:ListItem Value="ninth">9th District</asp:ListItem>
    <asp:ListItem Value="tenth">10th District</asp:ListItem>
    </asp:dropdownlist>

    -Darrel
     
    darrel, Aug 26, 2005
    #7
  8. darrel

    darrel Guest

    > If your ddl is reverting to the first item and not keeping the selected
    > item from prior to the postback, you are probably calling databind() on
    > the control on the postback.


    I'm not in this case. Just a static list of asp:listItems

    Nowhere in my codebehind am I databinding to this list nor am I even
    changing the selected item.

    -Darrel
     
    darrel, Aug 26, 2005
    #8
  9. darrel

    Marina Guest

    Have you recompiled your project since adding the handler?

    If this is all that is going on, then the handler should be getting hit.

    "darrel" <> wrote in message
    news:%...
    >> Do they all have unique values?

    >
    > Yes. Here's the full markup:
    >
    > <asp:dropdownlist id=ddl_districtSelect runat="server"
    > AutoPostBack="True">
    > <asp:ListItem Value="first">1st District</asp:ListItem>
    > <asp:ListItem Value="second">2nd District</asp:ListItem>
    > <asp:ListItem Value="third">3rd District</asp:ListItem>
    > <asp:ListItem Value="fourth">4th District</asp:ListItem>
    > <asp:ListItem Value="fifth">5th District</asp:ListItem>
    > <asp:ListItem Value="sixth">6th District</asp:ListItem>
    > <asp:ListItem Value="seventh">7th District</asp:ListItem>
    > <asp:ListItem Value="eigth">8th District</asp:ListItem>
    > <asp:ListItem Value="ninth">9th District</asp:ListItem>
    > <asp:ListItem Value="tenth">10th District</asp:ListItem>
    > </asp:dropdownlist>
    >
    > -Darrel
    >
    >
     
    Marina, Aug 26, 2005
    #9
  10. darrel

    darrel Guest

    > Have you recompiled your project since adding the handler?
    >
    > If this is all that is going on, then the handler should be getting hit.


    Aaarrrrrrrrrrrrrrggggggggggghhhhhhhhhhhhhhh!

    I'm a dope. Turns out there was a stray FORM tag in the HTML (this was a
    legacy ASP page that I'm slowly converting).

    'doh!

    -Darrel
     
    darrel, Aug 26, 2005
    #10
  11. darrel

    John Horst Guest

    What is the EnableViewState property on the ddl set to? It should be
    True.

    John

    -----Original Message-----
    From: darrel [mailto:]
    Posted At: Friday, August 26, 2005 1:27 PM
    Posted To: microsoft.public.dotnet.framework.aspnet
    Conversation: My DropDownList handler isn't executing.
    Subject: Re: My DropDownList handler isn't executing.


    > If your ddl is reverting to the first item and not keeping the
    > selected item from prior to the postback, you are probably calling
    > databind() on the control on the postback.


    I'm not in this case. Just a static list of asp:listItems

    Nowhere in my codebehind am I databinding to this list nor am I even
    changing the selected item.

    -Darrel
     
    John Horst, Aug 26, 2005
    #11
  12. darrel

    darrel Guest

    > What is the EnableViewState property on the ddl set to? It should be
    > True.
    >
    > John


    Hey John. See my other response. THis was a user-error problem. I was
    migrating an old ASP page over and had missed a stray FORM tag that was
    breaking everything below it.

    A typical Friday mind fart on my part. ;o)

    -Darrel
     
    darrel, Aug 26, 2005
    #12
  13. darrel

    Pat Guest

    Darrel good you got it working

    "darrel" <> wrote in message
    news:...
    > > Have you recompiled your project since adding the handler?
    > >
    > > If this is all that is going on, then the handler should be getting hit.

    >
    > Aaarrrrrrrrrrrrrrggggggggggghhhhhhhhhhhhhhh!
    >
    > I'm a dope. Turns out there was a stray FORM tag in the HTML (this was a
    > legacy ASP page that I'm slowly converting).
    >
    > 'doh!
    >
    > -Darrel
    >
    >
     
    Pat, Aug 29, 2005
    #13
    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. Replies:
    0
    Views:
    696
  2. Replies:
    10
    Views:
    716
    Ingo R. Homann
    Apr 20, 2006
  3. Sergio E.

    event handler isn't working

    Sergio E., Aug 19, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    325
    Sergio E.
    Aug 19, 2007
  4. Replies:
    3
    Views:
    278
    red floyd
    Feb 13, 2008
  5. Sergio E.

    event handler isn't working

    Sergio E., Aug 19, 2007, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    774
    Sergio E.
    Sep 11, 2007
Loading...

Share This Page