Dynamically (in code) add a Event Proc Prop??

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Groove

    #1

    Dynamically (in code) add a Event Proc Prop??

    This might be fairly easy to do. Hopefully, it is.

    (asp.net 2 / vb)

    I have a Drop Down List and in th code-behind vb file, I'd like to
    optionally add a OnSelectedIndex Changed attribute to it. Depending on
    whether certain conditions are met when the page loads, I'd like to be able
    to optionally add this attribute to my DDL. Does this make sense? I tried
    using this but it doesn't work:

    ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
    "ddlExpenseItem s_SelectedIndex Change")

    This shows up in the html source code:
    OnSelectedIndex Changed="ddlExp enseItems_Selec tedIndexChange"


    Essentially what I'm trying to accomplish is that **under certain
    conditions**, require the user to provide a brief explaination if they chose
    "Other" in the DDL. The txtbox and RequiredValidat or become enabled. The
    trick is optionally making this DDL change on SelectedIndex. I don't want
    this to **always** be in place.


    Here's clips of my code.

    Sub Page_load
    If myVariable= True Then
    ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
    "ddlExpenseItem s_SelectedIndex Change")
    End If
    End Sub



    Protected Sub ddlExpenseItems _SelectedIndexC hange(ByVal Sender As Object,
    ByVal E As EventArgs)

    If ddlOperatingIte ms.SelectedValu e = XXX Then
    txtOtherDescrip tion.Enabled = True
    txtOtherDescrip tion.Text = ""
    OtherDescRequir ed.Enabled = True
    Else
    txtOtherDescrip tion.Enabled = False
    txtOtherDescrip tion.Text = "Not Required"
    OtherDescRequir ed.Enabled = False
    End If

    End Sub






  • Marina Levit [MVP]

    #2
    Re: Dynamically (in code) add a Event Proc Prop??

    You are adding a client side event handler. And I believe the javascript
    <select> object does not have an OnSelectedIndex Changed. This is a server
    side event only.

    To add server side events, use AddHandler.

    So, something ilke:

    AddHandler ddlOperatingIte ms.SelectedInde xChanged, AddressOf
    ddlExpenseItems _SelectedIndexC hanged

    "Groove" <noway@noemail. com> wrote in message
    news:eonIgLkhGH A.1508@TK2MSFTN GP04.phx.gbl...[color=blue]
    > This might be fairly easy to do. Hopefully, it is.
    >
    > (asp.net 2 / vb)
    >
    > I have a Drop Down List and in th code-behind vb file, I'd like to
    > optionally add a OnSelectedIndex Changed attribute to it. Depending on
    > whether certain conditions are met when the page loads, I'd like to be
    > able to optionally add this attribute to my DDL. Does this make sense? I
    > tried using this but it doesn't work:
    >
    > ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
    > "ddlExpenseItem s_SelectedIndex Change")
    >
    > This shows up in the html source code:
    > OnSelectedIndex Changed="ddlExp enseItems_Selec tedIndexChange"
    >
    >
    > Essentially what I'm trying to accomplish is that **under certain
    > conditions**, require the user to provide a brief explaination if they
    > chose "Other" in the DDL. The txtbox and RequiredValidat or become
    > enabled. The trick is optionally making this DDL change on SelectedIndex.
    > I don't want this to **always** be in place.
    >
    >
    > Here's clips of my code.
    >
    > Sub Page_load
    > If myVariable= True Then
    > ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
    > "ddlExpenseItem s_SelectedIndex Change")
    > End If
    > End Sub
    >
    >
    >
    > Protected Sub ddlExpenseItems _SelectedIndexC hange(ByVal Sender As Object,
    > ByVal E As EventArgs)
    >
    > If ddlOperatingIte ms.SelectedValu e = XXX Then
    > txtOtherDescrip tion.Enabled = True
    > txtOtherDescrip tion.Text = ""
    > OtherDescRequir ed.Enabled = True
    > Else
    > txtOtherDescrip tion.Enabled = False
    > txtOtherDescrip tion.Text = "Not Required"
    > OtherDescRequir ed.Enabled = False
    > End If
    >
    > End Sub
    >
    >
    >
    >
    >
    >[/color]


    Comment

    • Groove

      #3
      Re: Dynamically (in code) add a Event Proc Prop??

      Thanks!

      I added this:
      AddHandler ddlOperatingIte ms.SelectedInde xChanged, AddressOf
      ddlExpenseItems _SelectedIndexC hange

      to my code in page_load and nothing seems to happen when change the values
      in the DDL. I'm NOT testing for PostBack so it should be loading this each
      and every time. VWD Express isn't indicating any syntax errors and the page
      compiles and loads fine. Just nothing happens.

      Any ideas?



      Thanks







      "Marina Levit [MVP]" <someone@nospam .com> wrote in message
      news:uQONoOkhGH A.2188@TK2MSFTN GP04.phx.gbl...[color=blue]
      > You are adding a client side event handler. And I believe the javascript
      > <select> object does not have an OnSelectedIndex Changed. This is a server
      > side event only.
      >
      > To add server side events, use AddHandler.
      >
      > So, something ilke:
      >
      > AddHandler ddlOperatingIte ms.SelectedInde xChanged, AddressOf
      > ddlExpenseItems _SelectedIndexC hanged
      >
      > "Groove" <noway@noemail. com> wrote in message
      > news:eonIgLkhGH A.1508@TK2MSFTN GP04.phx.gbl...[color=green]
      >> This might be fairly easy to do. Hopefully, it is.
      >>
      >> (asp.net 2 / vb)
      >>
      >> I have a Drop Down List and in th code-behind vb file, I'd like to
      >> optionally add a OnSelectedIndex Changed attribute to it. Depending on
      >> whether certain conditions are met when the page loads, I'd like to be
      >> able to optionally add this attribute to my DDL. Does this make sense?
      >> I tried using this but it doesn't work:
      >>
      >> ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
      >> "ddlExpenseItem s_SelectedIndex Change")
      >>
      >> This shows up in the html source code:
      >> OnSelectedIndex Changed="ddlExp enseItems_Selec tedIndexChange"
      >>
      >>
      >> Essentially what I'm trying to accomplish is that **under certain
      >> conditions**, require the user to provide a brief explaination if they
      >> chose "Other" in the DDL. The txtbox and RequiredValidat or become
      >> enabled. The trick is optionally making this DDL change on
      >> SelectedIndex. I don't want this to **always** be in place.
      >>
      >>
      >> Here's clips of my code.
      >>
      >> Sub Page_load
      >> If myVariable= True Then
      >> ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
      >> "ddlExpenseItem s_SelectedIndex Change")
      >> End If
      >> End Sub
      >>
      >>
      >>
      >> Protected Sub ddlExpenseItems _SelectedIndexC hange(ByVal Sender As Object,
      >> ByVal E As EventArgs)
      >>
      >> If ddlOperatingIte ms.SelectedValu e = XXX Then
      >> txtOtherDescrip tion.Enabled = True
      >> txtOtherDescrip tion.Text = ""
      >> OtherDescRequir ed.Enabled = True
      >> Else
      >> txtOtherDescrip tion.Enabled = False
      >> txtOtherDescrip tion.Text = "Not Required"
      >> OtherDescRequir ed.Enabled = False
      >> End If
      >>
      >> End Sub
      >>
      >>
      >>
      >>
      >>
      >>[/color]
      >
      >[/color]


      Comment

      • Groove

        #4
        Re: Dynamically (in code) add a Event Proc Prop??

        Nevermind. I needed to add AutoPostback = True.

        Thanks!


        "Groove" <noway@noemail. com> wrote in message
        news:O1Sa%23hkh GHA.2208@TK2MSF TNGP05.phx.gbl. ..[color=blue]
        > Thanks!
        >
        > I added this:
        > AddHandler ddlOperatingIte ms.SelectedInde xChanged, AddressOf
        > ddlExpenseItems _SelectedIndexC hange
        >
        > to my code in page_load and nothing seems to happen when change the values
        > in the DDL. I'm NOT testing for PostBack so it should be loading this
        > each and every time. VWD Express isn't indicating any syntax errors and
        > the page compiles and loads fine. Just nothing happens.
        >
        > Any ideas?
        >
        >
        >
        > Thanks
        >
        >
        >
        >
        >
        >
        >
        > "Marina Levit [MVP]" <someone@nospam .com> wrote in message
        > news:uQONoOkhGH A.2188@TK2MSFTN GP04.phx.gbl...[color=green]
        >> You are adding a client side event handler. And I believe the javascript
        >> <select> object does not have an OnSelectedIndex Changed. This is a server
        >> side event only.
        >>
        >> To add server side events, use AddHandler.
        >>
        >> So, something ilke:
        >>
        >> AddHandler ddlOperatingIte ms.SelectedInde xChanged, AddressOf
        >> ddlExpenseItems _SelectedIndexC hanged
        >>
        >> "Groove" <noway@noemail. com> wrote in message
        >> news:eonIgLkhGH A.1508@TK2MSFTN GP04.phx.gbl...[color=darkred]
        >>> This might be fairly easy to do. Hopefully, it is.
        >>>
        >>> (asp.net 2 / vb)
        >>>
        >>> I have a Drop Down List and in th code-behind vb file, I'd like to
        >>> optionally add a OnSelectedIndex Changed attribute to it. Depending on
        >>> whether certain conditions are met when the page loads, I'd like to be
        >>> able to optionally add this attribute to my DDL. Does this make sense?
        >>> I tried using this but it doesn't work:
        >>>
        >>> ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
        >>> "ddlExpenseItem s_SelectedIndex Change")
        >>>
        >>> This shows up in the html source code:
        >>> OnSelectedIndex Changed="ddlExp enseItems_Selec tedIndexChange"
        >>>
        >>>
        >>> Essentially what I'm trying to accomplish is that **under certain
        >>> conditions**, require the user to provide a brief explaination if they
        >>> chose "Other" in the DDL. The txtbox and RequiredValidat or become
        >>> enabled. The trick is optionally making this DDL change on
        >>> SelectedIndex. I don't want this to **always** be in place.
        >>>
        >>>
        >>> Here's clips of my code.
        >>>
        >>> Sub Page_load
        >>> If myVariable= True Then
        >>> ddlOperatingIte ms.Attributes.A dd("OnSelectedI ndexChanged",
        >>> "ddlExpenseItem s_SelectedIndex Change")
        >>> End If
        >>> End Sub
        >>>
        >>>
        >>>
        >>> Protected Sub ddlExpenseItems _SelectedIndexC hange(ByVal Sender As
        >>> Object, ByVal E As EventArgs)
        >>>
        >>> If ddlOperatingIte ms.SelectedValu e = XXX Then
        >>> txtOtherDescrip tion.Enabled = True
        >>> txtOtherDescrip tion.Text = ""
        >>> OtherDescRequir ed.Enabled = True
        >>> Else
        >>> txtOtherDescrip tion.Enabled = False
        >>> txtOtherDescrip tion.Text = "Not Required"
        >>> OtherDescRequir ed.Enabled = False
        >>> End If
        >>>
        >>> End Sub
        >>>
        >>>
        >>>
        >>>
        >>>
        >>>[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        Working...