dropdownlist - hooking into the onselectedindexchanged event renders onchange html attribute

Discussion in 'ASP .Net Building Controls' started by TS, Jul 27, 2007.

  1. TS

    TS Guest

    i have an inherited ddl and i have a property (OnChangeFunction) that when
    set will add an onchange attribute to it which will call the JavaScript
    method used in (OnChangeFunction). the problem is that it interacts with the
    one created when assigning onselectedindexchanged to a server side event
    handler; so what happens is two onchange html attributes are rendered.

    i want to make it so my JS function call (specified in OnChangeFunction)
    gets added as the first item in the onchange html attirbute when the
    onselectedindexchanged is used, otherwise manually create the onchange
    attribute.

    what can i do?

    thanks
    TS, Jul 27, 2007
    #1
    1. Advertising

  2. Hi TS,

    Without full code listing, I cannot reproduce the issue on my side clearly.
    However, it's recommended to add your javascript or assign javascript
    functions to the client-side events in OnPreRender:

    public class Class1 : DropDownList
    {

    protected override void OnPreRender(EventArgs e)
    {
    Attributes.Add("onchange", "javascript:alert('changed!')");

    base.OnPreRender(e);
    }
    }


    Please post your code here if this doesn't help. Thanks.


    Regards,
    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Jul 30, 2007
    #2
    1. Advertising

  3. TS

    TS Guest

    that works, thanks

    "Walter Wang [MSFT]" <> wrote in message
    news:...
    > Hi TS,
    >
    > Without full code listing, I cannot reproduce the issue on my side

    clearly.
    > However, it's recommended to add your javascript or assign javascript
    > functions to the client-side events in OnPreRender:
    >
    > public class Class1 : DropDownList
    > {
    >
    > protected override void OnPreRender(EventArgs e)
    > {
    > Attributes.Add("onchange", "javascript:alert('changed!')");
    >
    > base.OnPreRender(e);
    > }
    > }
    >
    >
    > Please post your code here if this doesn't help. Thanks.
    >
    >
    > Regards,
    > Walter Wang (, remove 'online.')
    > Microsoft Online Community Support
    >
    > ==================================================
    > When responding to posts, please "Reply to Group" via your newsreader so
    > that others may learn and benefit from your issue.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no

    rights.
    >
    TS, Jul 30, 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. Alexander Reichman

    Dropdownlist onselectedIndexChanged event not fires

    Alexander Reichman, Oct 17, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    23,309
  2. Paul L
    Replies:
    1
    Views:
    7,294
  3. Replies:
    8
    Views:
    758
  4. PJ
    Replies:
    0
    Views:
    550
  5. =?Utf-8?B?Z2xlbm4=?=

    DropDownList control and OnSelectedIndexChanged event

    =?Utf-8?B?Z2xlbm4=?=, Apr 21, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    8,345
    =?Utf-8?B?Y2xpY2tvbg==?=
    Apr 21, 2006
Loading...

Share This Page