ByVal sender As Object, ByVal e As EventArgs - can I send more?

Discussion in 'ASP .Net Web Controls' started by David Lozzi, Jul 22, 2005.

  1. David Lozzi

    David Lozzi Guest

    I have the following drop down list:

    <asp:DropDownList id="ddDept" runat="server" DataSource='<%#
    LoadDropDown("DEPT") %>' DataTextField="strName" DataValueField="strName"
    AutoPostBack="True"
    OnSelectedIndexChanged="UpdateText('txtDepartment')"></asp:DropDownList>

    and on change I would like the value of the drop down to populate a text
    box. Here's the function:

    Sub UpdateText(ByVal sender As Object, ByVal e As EventArgs, ByVal txt
    As String)
    Dim dd As DropDownList = sender
    Dim tx as TextBox
    tx = dd.Parent.FindControl(txt)
    'tx = dd.Parent.FindControl("txtDepartment")
    If dd.SelectedIndex > 0 Then
    tx.Text = dd.SelectedValue
    End If
    End Sub

    Now, i just added the references to tx as textbox and that's where I get the
    issues. If I remove that and uncomment the line that finds the control it
    works great! However, I have several drop downs that I want to use this
    function with so I don't want to make several of the same functions.

    Is there a way to send data to a Sub/function from the drop down and keep
    the sender object? Is there a way to send the drop down object and another
    variable to the sub/function? Something like this in Javascript works:
    onchange="UpdateText(this,'txtDepartment')". Of course I don't want to use
    javascript, I want it all done in the code.

    Thanks!

    David Lozzi
    David Lozzi, Jul 22, 2005
    #1
    1. Advertising

  2. David Lozzi

    David Lozzi Guest

    Is it possible to do something like this instead?

    OnSelectedIndexChanged="UpdateText(txtDepartment,ddDept)"

    Function UpdateText(ByVal txt As TextBox, ByVal ddl As DropDownList)



    If ddl.SelectedIndex > 0 Then

    txt.Text = ddl.SelectedValue

    End If

    End Function


    Currently, i get this error:

    'AddressOf' operand must be the name of a method; no parentheses are needed


    thanks!


    "David Lozzi" <dlozzi@(removethis)delphi-ts.com> wrote in message
    news:...
    >I have the following drop down list:
    >
    > <asp:DropDownList id="ddDept" runat="server" DataSource='<%#
    > LoadDropDown("DEPT") %>' DataTextField="strName" DataValueField="strName"
    > AutoPostBack="True"
    > OnSelectedIndexChanged="UpdateText('txtDepartment')"></asp:DropDownList>
    >
    > and on change I would like the value of the drop down to populate a text
    > box. Here's the function:
    >
    > Sub UpdateText(ByVal sender As Object, ByVal e As EventArgs, ByVal txt
    > As String)
    > Dim dd As DropDownList = sender
    > Dim tx as TextBox
    > tx = dd.Parent.FindControl(txt)
    > 'tx = dd.Parent.FindControl("txtDepartment")
    > If dd.SelectedIndex > 0 Then
    > tx.Text = dd.SelectedValue
    > End If
    > End Sub
    >
    > Now, i just added the references to tx as textbox and that's where I get
    > the issues. If I remove that and uncomment the line that finds the control
    > it works great! However, I have several drop downs that I want to use this
    > function with so I don't want to make several of the same functions.
    >
    > Is there a way to send data to a Sub/function from the drop down and keep
    > the sender object? Is there a way to send the drop down object and another
    > variable to the sub/function? Something like this in Javascript works:
    > onchange="UpdateText(this,'txtDepartment')". Of course I don't want to use
    > javascript, I want it all done in the code.
    >
    > Thanks!
    >
    > David Lozzi
    >
    >
    David Lozzi, Jul 22, 2005
    #2
    1. Advertising

  3. David Lozzi

    Harolds Guest

    Re: ByVal sender As Object, ByVal e As EventArgs - can I send m

    Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    handles ddlA.SelectedIndexChanged, ddlB.SelectedIndexChanged,
    ddlC.SelectedIndexChanged
    dim txt as textbox
    If ctype(sender,DropDownList).SelectedIndex > 0 Then
    select case ctype(sender,DropDownList).id
    case "ddlA"
    txt = findcontrol("txtA")
    case "ddlB"
    txt = findcontrol("txtB")
    case "ddlC"
    txt = findcontrol("txtC")
    end select
    txt.text = sender.selectvalue
    end if



    "David Lozzi" wrote:

    > Is it possible to do something like this instead?
    >
    > OnSelectedIndexChanged="UpdateText(txtDepartment,ddDept)"
    >
    > Function UpdateText(ByVal txt As TextBox, ByVal ddl As DropDownList)
    >
    >
    >
    > If ddl.SelectedIndex > 0 Then
    >
    > txt.Text = ddl.SelectedValue
    >
    > End If
    >
    > End Function
    >
    >
    > Currently, i get this error:
    >
    > 'AddressOf' operand must be the name of a method; no parentheses are needed
    >
    >
    > thanks!
    >
    >
    > "David Lozzi" <dlozzi@(removethis)delphi-ts.com> wrote in message
    > news:...
    > >I have the following drop down list:
    > >
    > > <asp:DropDownList id="ddDept" runat="server" DataSource='<%#
    > > LoadDropDown("DEPT") %>' DataTextField="strName" DataValueField="strName"
    > > AutoPostBack="True"
    > > OnSelectedIndexChanged="UpdateText('txtDepartment')"></asp:DropDownList>
    > >
    > > and on change I would like the value of the drop down to populate a text
    > > box. Here's the function:
    > >
    > > Sub UpdateText(ByVal sender As Object, ByVal e As EventArgs, ByVal txt
    > > As String)
    > > Dim dd As DropDownList = sender
    > > Dim tx as TextBox
    > > tx = dd.Parent.FindControl(txt)
    > > 'tx = dd.Parent.FindControl("txtDepartment")
    > > If dd.SelectedIndex > 0 Then
    > > tx.Text = dd.SelectedValue
    > > End If
    > > End Sub
    > >
    > > Now, i just added the references to tx as textbox and that's where I get
    > > the issues. If I remove that and uncomment the line that finds the control
    > > it works great! However, I have several drop downs that I want to use this
    > > function with so I don't want to make several of the same functions.
    > >
    > > Is there a way to send data to a Sub/function from the drop down and keep
    > > the sender object? Is there a way to send the drop down object and another
    > > variable to the sub/function? Something like this in Javascript works:
    > > onchange="UpdateText(this,'txtDepartment')". Of course I don't want to use
    > > javascript, I want it all done in the code.
    > >
    > > Thanks!
    > >
    > > David Lozzi
    > >
    > >

    >
    >
    >
    Harolds, Jul 22, 2005
    #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. David Waz...
    Replies:
    0
    Views:
    399
    David Waz...
    Jul 4, 2003
  2. Kathy Burke
    Replies:
    2
    Views:
    5,118
    Kevin Spencer
    Aug 1, 2003
  3. Showjumper
    Replies:
    2
    Views:
    1,789
    Showjumper
    Aug 2, 2003
  4. mswc.net
    Replies:
    2
    Views:
    635
    Kevin Spencer
    Apr 26, 2005
  5. Andreas Klemt
    Replies:
    1
    Views:
    123
    Tim Pacl
    Jul 18, 2003
Loading...

Share This Page