Raising event from run-time dropdownlist

Discussion in 'ASP .Net' started by Andrew Morton, Sep 19, 2007.

  1. I'm creating DropDownList controls at run-time, and I've found I have to add
    the onchange event myself (.Attributes.Add(...) below).

    Is that the way it's meant to happen, or have I missed something that would
    automatically add the onchange event?

    U = New DropDownList
    With U
    .DataSource = dv
    .DataTextField = "myChoice"
    .DataValueField = "myValue"
    .DataBind()
    ' n is the number of this control
    .ID = "U_" & n.ToString
    ' select the current value
    For k As Integer = 0 To UBound(usageValues)
    If CStr(entry("usage")) = usageValues(k) Then
    .SelectedIndex = k
    Exit For
    End If
    Next
    AddHandler .SelectedIndexChanged, AddressOf
    ModifyUsage_SelectedIndexChanged
    .Attributes.Add("onchange", "__doPostBack('U_" & n.ToString & "')")
    End With

    Andrew
     
    Andrew Morton, Sep 19, 2007
    #1
    1. Advertising

  2. Andrew Morton

    bruce barker Guest

    you want to set AutoPostBack.

    -- bruce (sqlwork.com)



    Andrew Morton wrote:
    > I'm creating DropDownList controls at run-time, and I've found I have to add
    > the onchange event myself (.Attributes.Add(...) below).
    >
    > Is that the way it's meant to happen, or have I missed something that would
    > automatically add the onchange event?
    >
    > U = New DropDownList
    > With U
    > .DataSource = dv
    > .DataTextField = "myChoice"
    > .DataValueField = "myValue"
    > .DataBind()
    > ' n is the number of this control
    > .ID = "U_" & n.ToString
    > ' select the current value
    > For k As Integer = 0 To UBound(usageValues)
    > If CStr(entry("usage")) = usageValues(k) Then
    > .SelectedIndex = k
    > Exit For
    > End If
    > Next
    > AddHandler .SelectedIndexChanged, AddressOf
    > ModifyUsage_SelectedIndexChanged
    > .Attributes.Add("onchange", "__doPostBack('U_" & n.ToString & "')")
    > End With
    >
    > Andrew
    >
    >
     
    bruce barker, Sep 19, 2007
    #2
    1. Advertising

  3. > Andrew Morton wrote:
    >> I'm creating DropDownList controls at run-time, and I've found I
    >> have to add the onchange event myself (.Attributes.Add(...) below).
    >>
    >> Is that the way it's meant to happen, or have I missed something
    >> that would automatically add the onchange event?


    bruce barker wrote:
    > you want to set AutoPostBack.


    Aha! Thanks :)

    Andrew
     
    Andrew Morton, Sep 20, 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. Dane Dickey

    Raising an Event via Code

    Dane Dickey, Jun 30, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    389
    Natty Gur
    Jul 1, 2003
  2. Kevin Spencer

    Re: raising event

    Kevin Spencer, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    Kevin Spencer
    Jul 31, 2003
  3. Jitu
    Replies:
    0
    Views:
    401
  4. Jeremy Howard
    Replies:
    0
    Views:
    1,249
    Jeremy Howard
    Feb 15, 2004
  5. Pierre Yves
    Replies:
    2
    Views:
    499
    Pierre Yves
    Jan 10, 2008
Loading...

Share This Page