event handler isn't working

Discussion in 'ASP .Net Building Controls' started by Sergio E., Aug 19, 2007.

  1. Sergio E.

    Sergio E. Guest

    Hello, I am extending a webcontrol, and I need to generate an array of
    objects of type dropdownlist, whose event selectedindexchanged must fires an
    own method called Cbo_SelectedIndexChanged that has the same signature of
    selectedindexchanged of a normal dropdownlist. I already tried to add the
    handler to them with addhandler but the event does not go off. I already
    debug it line by line and the first timethe page with the control draws
    correctly, dropdownlists fill correctly but when changing some value of any
    of them it does not work, the method never is reached. I don't know if it is
    because I don't defined the withevents modifier for each dropdownlist, but
    the compiler gives me an error if I do "protected withevents cbos() as
    dropdownlist" and I don't know how add to it when it's in an array.

    The source code involved is this:

    public class myExtendedPanel
    inherits panel
    protected cbos() as dropdownlist

    private sub GenerateCbos(byval maxcbos as integer)
    redim me.cbos(0 to maxcbos)
    for i as integer = 0 to maxcbos
    me.cbos(i) = new dropdownlist()
    me.cbos(i).id="LocalCbo"+i.tostring()
    me.cbos(i).datasource = me.dts(i)
    me.cbos(i).datatextfield="colText"
    me.cbos(i).datavaluefield="colId"
    me.cbos(i).autopostback=true
    me.cbos(i).enableviewstate=true
    Dim eh As EventHandler = New EventHandler(AddressOf
    Me.Cbo_SelectedIndexChanged)
    AddHandler Me.ddls(i).SelectedIndexChanged, eh
    'AddHandler ddl.SelectedIndexChanged, AddressOf Me.Cbo_SelectedIndexChanged
    ' it don't work too
    me.cbos(i).databind()
    me.cbos(i).selectedvalue=me.selvals(i)
    me.controls.add(me.cbos(i))
    next
    end sub


    Protected Sub Cbo_SelectedIndexChanged(ByVal sender As Object, ByVal e As
    EventArgs)
    'Here goes the code to execute, by now i use a test
    response.write(me.cbos(0).selectedvalue)
    'this method hasn't reached
    end sub
    end class


    What I'm doing wrong?
    Thank you!
    --
    Greetings,
    Sergio E.
    Sergio E., Aug 19, 2007
    #1
    1. Advertising

  2. One thing that I am noticing is that you do not declare Me.ddls anywhere
    (the object you use in the AddHandler statement). Also, it looks to me like
    you are not very experienced in writing custom controls; by this I am
    referring to the fact that you are not overriding the methods defined in the
    WebControl class that are normally overridden in custom controls. For
    example, CreateChildControls. For more information see the documentation.
    Also, a great book with plenty of simple yet complete examples that are
    explained in much detail is ASP.NET 2.0 Unleashed by Stephen Walther:

    http://www.amazon.com/ASP-NET-2-0-U...352937-2405450?ie=UTF8&qid=1189389819&sr=11-1

    Another suggestion of mine, based on your code, would be to not inherit from
    the Panel control, but from the WebControl. Assuming you are not using any
    of the capabilities unique to the Panel, your control may be more efficient
    if you inherit from WebControl. Good Luck!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Sergio E." <gruporemp[ARROBA]hotmail.com> wrote in message
    news:...
    > Hello, I am extending a webcontrol, and I need to generate an array of
    > objects of type dropdownlist, whose event selectedindexchanged must fires
    > an own method called Cbo_SelectedIndexChanged that has the same signature
    > of selectedindexchanged of a normal dropdownlist. I already tried to add
    > the handler to them with addhandler but the event does not go off. I
    > already debug it line by line and the first timethe page with the control
    > draws correctly, dropdownlists fill correctly but when changing some value
    > of any of them it does not work, the method never is reached. I don't know
    > if it is because I don't defined the withevents modifier for each
    > dropdownlist, but the compiler gives me an error if I do "protected
    > withevents cbos() as dropdownlist" and I don't know how add to it when
    > it's in an array.
    >
    > The source code involved is this:
    >
    > public class myExtendedPanel
    > inherits panel
    > protected cbos() as dropdownlist
    >
    > private sub GenerateCbos(byval maxcbos as integer)
    > redim me.cbos(0 to maxcbos)
    > for i as integer = 0 to maxcbos
    > me.cbos(i) = new dropdownlist()
    > me.cbos(i).id="LocalCbo"+i.tostring()
    > me.cbos(i).datasource = me.dts(i)
    > me.cbos(i).datatextfield="colText"
    > me.cbos(i).datavaluefield="colId"
    > me.cbos(i).autopostback=true
    > me.cbos(i).enableviewstate=true
    > Dim eh As EventHandler = New EventHandler(AddressOf
    > Me.Cbo_SelectedIndexChanged)
    > AddHandler Me.ddls(i).SelectedIndexChanged, eh
    > 'AddHandler ddl.SelectedIndexChanged, AddressOf
    > Me.Cbo_SelectedIndexChanged ' it don't work too
    > me.cbos(i).databind()
    > me.cbos(i).selectedvalue=me.selvals(i)
    > me.controls.add(me.cbos(i))
    > next
    > end sub
    >
    >
    > Protected Sub Cbo_SelectedIndexChanged(ByVal sender As Object, ByVal e As
    > EventArgs)
    > 'Here goes the code to execute, by now i use a test
    > response.write(me.cbos(0).selectedvalue)
    > 'this method hasn't reached
    > end sub
    > end class
    >
    >
    > What I'm doing wrong?
    > Thank you!
    > --
    > Greetings,
    > Sergio E.
    >
    >
    >
    Nathan Sokalski, Sep 10, 2007
    #2
    1. Advertising

  3. Sergio E.

    Sergio E. Guest

    thanks for the information, i'll try to get that book..

    greetings
    Sergio E


    "Nathan Sokalski" <> escribió en el mensaje
    news:OZ$UM%...
    > One thing that I am noticing is that you do not declare Me.ddls anywhere
    > (the object you use in the AddHandler statement). Also, it looks to me
    > like you are not very experienced in writing custom controls; by this I am
    > referring to the fact that you are not overriding the methods defined in
    > the WebControl class that are normally overridden in custom controls. For
    > example, CreateChildControls. For more information see the documentation.
    > Also, a great book with plenty of simple yet complete examples that are
    > explained in much detail is ASP.NET 2.0 Unleashed by Stephen Walther:
    >
    > http://www.amazon.com/ASP-NET-2-0-U...352937-2405450?ie=UTF8&qid=1189389819&sr=11-1
    >
    > Another suggestion of mine, based on your code, would be to not inherit
    > from the Panel control, but from the WebControl. Assuming you are not
    > using any of the capabilities unique to the Panel, your control may be
    > more efficient if you inherit from WebControl. Good Luck!
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
    > "Sergio E." <gruporemp[ARROBA]hotmail.com> wrote in message
    > news:...
    >> Hello, I am extending a webcontrol, and I need to generate an array of
    >> objects of type dropdownlist, whose event selectedindexchanged must fires
    >> an own method called Cbo_SelectedIndexChanged that has the same signature
    >> of selectedindexchanged of a normal dropdownlist. I already tried to add
    >> the handler to them with addhandler but the event does not go off. I
    >> already debug it line by line and the first timethe page with the control
    >> draws correctly, dropdownlists fill correctly but when changing some
    >> value of any of them it does not work, the method never is reached. I
    >> don't know if it is because I don't defined the withevents modifier for
    >> each dropdownlist, but the compiler gives me an error if I do "protected
    >> withevents cbos() as dropdownlist" and I don't know how add to it when
    >> it's in an array.
    >>
    >> The source code involved is this:
    >>
    >> public class myExtendedPanel
    >> inherits panel
    >> protected cbos() as dropdownlist
    >>
    >> private sub GenerateCbos(byval maxcbos as integer)
    >> redim me.cbos(0 to maxcbos)
    >> for i as integer = 0 to maxcbos
    >> me.cbos(i) = new dropdownlist()
    >> me.cbos(i).id="LocalCbo"+i.tostring()
    >> me.cbos(i).datasource = me.dts(i)
    >> me.cbos(i).datatextfield="colText"
    >> me.cbos(i).datavaluefield="colId"
    >> me.cbos(i).autopostback=true
    >> me.cbos(i).enableviewstate=true
    >> Dim eh As EventHandler = New EventHandler(AddressOf
    >> Me.Cbo_SelectedIndexChanged)
    >> AddHandler Me.ddls(i).SelectedIndexChanged, eh
    >> 'AddHandler ddl.SelectedIndexChanged, AddressOf
    >> Me.Cbo_SelectedIndexChanged ' it don't work too
    >> me.cbos(i).databind()
    >> me.cbos(i).selectedvalue=me.selvals(i)
    >> me.controls.add(me.cbos(i))
    >> next
    >> end sub
    >>
    >>
    >> Protected Sub Cbo_SelectedIndexChanged(ByVal sender As Object, ByVal e As
    >> EventArgs)
    >> 'Here goes the code to execute, by now i use a test
    >> response.write(me.cbos(0).selectedvalue)
    >> 'this method hasn't reached
    >> end sub
    >> end class
    >>
    >>
    >> What I'm doing wrong?
    >> Thank you!
    >> --
    >> Greetings,
    >> Sergio E.
    >>
    >>
    >>

    >
    >
    Sergio E., Sep 11, 2007
    #3
    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:
    674
  2. Replies:
    1
    Views:
    695
    Damien
    Feb 22, 2007
  3. Sergio E.

    event handler isn't working

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

    event handler isn't working

    Sergio E., Aug 19, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    140
    Sergio E.
    Aug 19, 2007
Loading...

Share This Page