Selected Index event not firing

Discussion in 'ASP .Net' started by moondaddy, May 4, 2004.

  1. moondaddy

    moondaddy Guest

    I have a dropdown combo box on a form and I have its AutoPostBack property
    set to true. When I select something from the list it does a postback and
    then the Page_Load event fires followed by it's SelectedIndexChanged event.

    However, when I go back to this control again and select the first item in
    the list, it does a postback and the Page_Load event fires, but the
    SelectedIndexChanged doesn't fire. Why does the SelectedIndexChanged get
    skipped when selecting the first item in the list?

    In summary, I have a dropdown list. I select the 3rd item in the list and
    the SelectedIndexChanged fires like it should. As I step through the code I
    see the selected index = 2. Now when I go back and select the first item in
    the list and step through the code I can see the selected index =0 (changed
    from 2), but the SelectedIndexChanged doesn't fire.

    How can I resolve this?

    Thanks.

    --
     
    moondaddy, May 4, 2004
    #1
    1. Advertising

  2. Make sure the event is defined (instantiated) in the IntializeComponent
    procedure.
    --
    Peter O'Reilly
     
    Peter O'Reilly, May 4, 2004
    #2
    1. Advertising

  3. moondaddy

    moondaddy Guest

    Can you give me an example of how I would do that? (vb.net if you can....)
    Its not in the IntializeComponent and its simply declared like this:

    Protected WithEvents cmbShipMethod As System.Web.UI.WebControls.DropDownList


    Thanks.

    --

    "Peter O'Reilly" <!N!O!.S!P!AM!> wrote in message
    news:...
    > Make sure the event is defined (instantiated) in the IntializeComponent
    > procedure.
    > --
    > Peter O'Reilly
    >
    >
     
    moondaddy, May 4, 2004
    #3
  4. moondaddy

    [MSFT] Guest

    Hello,

    Based on your description, I build a simple test web form. However, I
    haven't found the problem you mentioned. I just add some code in
    DropDownList1_SelectedIndexChanged:

    Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object,
    ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    Response.Write("changed")
    End Sub

    And add a breakpoint at the line. After run the application, the breakpoint
    get stopped whenever I select a item in the dropdown list control.

    Can you post some of your code to clarify the problem? Maybe we can get
    more detail informaiton from that.

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    [MSFT], May 5, 2004
    #4
  5. moondaddy

    [MSFT] Guest

    It is really a strange problem! After check your code, I found it seems to
    be related to your base page. If I added the control on a normal web form,
    it worked. Especially, with the MoveControl method in base page. Everytime
    we select a item, the code in MoveControls will be executed, and it cause
    the problem. If I remove the MoveControls, and add the control in another
    way:

    Public Class zTestDropdown
    Inherits BrowserTest.BasePage

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    Dim cc As Control = Page.LoadControl("shoppingcart.ascx")
    cc.Visible = True
    Me.ContentArea.Controls.Add(cc)
    End Sub

    This seems to fix the problem.

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    [MSFT], May 5, 2004
    #5
  6. moondaddy

    [MSFT] Guest

    Hello,

    This time the 'bad" line is:

    Me.cellContentContainer.Controls.Clear()

    If I replace it with

    Me.cellContentContainer.Controls.RemoveAt(0)

    Dim l1 As New LiteralControl
    Me.cellContentContainer.Controls.Add(l1)

    Me.cellContentContainer.Controls.Add(cc)

    Then it seem to work.

    Regarding all of these issues, I suggest you may consider frameset instead
    embed asp.net user control. For example, in the default.aspx:

    <td id="cellContentContainer" vAlign="top" bgColor="#ccccff" runat="server">

    <iframe src=home.aspx></iframe>

    </td>

    How about this?

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    [MSFT], May 6, 2004
    #6
  7. moondaddy

    moondaddy Guest

    I found one piece of information that may or may not lead to some insight:
    I re-created this page as a stand alone page (did not inherit from the
    basepage), and put all the html and code behind from the shoppingcart.ascx
    into shoppingcart.aspx and noticed I was still getting the same bad
    behavior. After testing it I found that cmbShipMethod's viewstate was
    false. After setting it to true, I found that everything worked OK. I'm
    sure that ealier I had tested viewstate as both true and false on everything
    I could find to see it that would help, but for some reason it helped on
    this new page. So I went back to the derived page with shoppingcart.ascx
    (the one I gave you in the above posting) and found that setting the
    viewstate to true or false had no effect on the behavior. My conclusion
    thus far is that there might be some problem with the dropdownlist's
    viewstate from the user control or because the page is inheriting from the
    base page, or a combo of both.

    --

    "moondaddy" <> wrote in message
    news:...
    > This is getting really confusing and frustrating. The code that didn't

    work
    > is code that was given to me in this user group. It worked under a

    previous
    > scenario, but not this one. How should one know when to use what syntax?
    > This isn't documented. I'm not coming down on you as you are being a

    great
    > help and I'm happy for that. However, as soon as the environment changes

    a
    > bit, the code doesn't work again and I have to ask you again for a

    solution.
    > Either I really don't know how to use the dropdown or it has some
    > shortcomings in these more complicated environments in which case the
    > development team needs to know about this if they don't already. OK

    enough
    > of that rant.
    >
    > Switching user controls is leading to lots of various problems so I'm

    going
    > with a slightly different model. This one is where each user control
    > (controls used for the main content of a page) get their own page and each
    > page inherits from the basepage. This way there's no confusion as to

    which
    > page a control is in. For example, the products.ascx lives in
    > products.aspx, aboutus.ascx lives in aboutus.aspx, and so on. Not as
    > elegant (or fast... I think) as one page-many controls, but more stable.
    >
    > So back to this troubled dropdown. Your code below worked when trading

    out
    > a control for another, but this time the shoppingcart control is constant

    in
    > the shoppingcart page and we're back to the same old problem.
    >
    > I'm attaching a new sample project. run this project using default.aspx

    as
    > the startup page and click
    > on the link on the left "Shoppingcart Test" to load the shopping cart for
    > testing. You will see what I mean. If you can help with this it would be
    > great as this is the model I think I'm going to go with.
    >
    > As for your comment about using frames. I wish I could. I spent the

    first
    > part of this project building it out in frames and it worked totally

    great.
    > but for reasons I have to do away with frames and so here I am.
    >
    > Thanks again!!!
    >
    > --
    >
    > "[MSFT]" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > This time the 'bad" line is:
    > >
    > > Me.cellContentContainer.Controls.Clear()
    > >
    > > If I replace it with
    > >
    > > Me.cellContentContainer.Controls.RemoveAt(0)
    > >
    > > Dim l1 As New LiteralControl
    > > Me.cellContentContainer.Controls.Add(l1)
    > >
    > > Me.cellContentContainer.Controls.Add(cc)
    > >
    > > Then it seem to work.
    > >
    > > Regarding all of these issues, I suggest you may consider frameset

    instead
    > > embed asp.net user control. For example, in the default.aspx:
    > >
    > > <td id="cellContentContainer" vAlign="top" bgColor="#ccccff"

    > runat="server">
    > >
    > > <iframe src=home.aspx></iframe>
    > >
    > > </td>
    > >
    > > How about this?
    > >
    > > Luke
    > > Microsoft Online Support
    > >
    > > Get Secure! www.microsoft.com/security
    > > (This posting is provided "AS IS", with no warranties, and confers no
    > > rights.)
    > >

    >
    >
    >
    >
    >
     
    moondaddy, May 7, 2004
    #7
  8. moondaddy

    [MSFT] Guest

    To get the event from controls. Viewstate is necessary. Regarding the
    issue, I can't open you sample project "BsPgSample", it reported an error
    when I open ShoppingCart.aspx. I check the code with Notepad and find the
    movecontrols method is still used. This may the root cause of the problem

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    [MSFT], May 7, 2004
    #8
  9. moondaddy

    moondaddy Guest

    I have to use the movecontrols method because the base page has table in it
    which is used to hold a user control for the header and another user control
    for the left nav bar. with our the movecontrols method, things dont get
    placed on the page correctly. the header and nav bar are on the bottom of
    the page.

    What kind of error did you get? could you open any other page? I would
    like to send you a working sample if possible. This whole thread stems from
    a shortage of good documentation and sample code for base pages in vb.net
    and I've spend a ton of time trying to get a solid model working. It would
    be nice if someone from MS could help in getting a proper base page working.
    Please let me know what I can do so send you a sample that runs.

    Thanks.

    --

    "[MSFT]" <> wrote in message
    news:5DOtmn$...
    > To get the event from controls. Viewstate is necessary. Regarding the
    > issue, I can't open you sample project "BsPgSample", it reported an error
    > when I open ShoppingCart.aspx. I check the code with Notepad and find the
    > movecontrols method is still used. This may the root cause of the problem
    >
    > Luke
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
     
    moondaddy, May 7, 2004
    #9
  10. moondaddy

    moondaddy Guest

    Thanks, I think this will fix the load problem: Attached are 2 text files,
    one with the base page html and the other with the code behind. Delete the
    existing base page out of the project I sent you (BsPgSample) and add a new
    webworm and call it "Base.aspx". Then add the html and code behind from the
    attached text files and it should run OK. Make sure that shopping.aspx
    inherits from the new base correctly (Inherits BsPgSample.Base).

    Please let me know if this fixed the load problem and what you can find out.

    --

    "[MSFT]" <> wrote in message
    news:...
    > I can open the solution. But when I double click to open

    shoppingcart.aspx,
    > there was an error. I have attached it in this message.
    >
    > Luke
     
    moondaddy, May 10, 2004
    #10
  11. moondaddy

    moondaddy Guest

    I hit send with out attaching the text files. here they are:

    --

    "[MSFT]" <> wrote in message
    news:...
    > I can open the solution. But when I double click to open

    shoppingcart.aspx,
    > there was an error. I have attached it in this message.
    >
    > Luke
     
    moondaddy, May 10, 2004
    #11
  12. moondaddy

    [MSFT] Guest

    Hello,

    I found two files are with same content:

    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="BasePage.aspx.vb" Inherits="BsPgSample.BasePage"%

    Did you miss the code behind file?

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    [MSFT], May 11, 2004
    #12
  13. moondaddy

    [MSFT] Guest

    Hello,

    Can you tell me what you want to do in selecteditemchanged actually? Maybe
    I can assis you find a final solution for the problem.

    regards,

    Luke
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    [MSFT], May 12, 2004
    #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. tshad
    Replies:
    5
    Views:
    5,982
    Joaquin Corchero
    Mar 15, 2005
  2. Andy
    Replies:
    1
    Views:
    815
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    Sep 29, 2005
  3. Anthony Papillion

    TkInter bind() event is not firing event trigger

    Anthony Papillion, Jun 23, 2010, in forum: Python
    Replies:
    3
    Views:
    1,699
    rantingrick
    Jun 23, 2010
  4. mldardy
    Replies:
    0
    Views:
    974
    mldardy
    Sep 28, 2010
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    317
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page