problem adding onlick attribute to Button from CodeBehind

Discussion in 'ASP .Net' started by Lars Netzel, Apr 7, 2005.

  1. Lars Netzel

    Lars Netzel Guest

    I have a simple aspx form where a few fields are validated with
    RequiredFieledValidators. They work fine..

    Now I needed to add an own onclick validation that checks something else and
    that has a errormessage that shoudl popup but it seems like I'm overwriting
    the onclick generated by .NET and the validations are not happening.

    I add the onclick as the last row in Page_Load
    btnSave.Attributes.Add("onclick", "javascript:return CheckInactive('" &
    Lang.GetText("customer_inactivewarning") & "');")

    I'm thinking I need to add this at a different time to NOT overwrite the
    onclick generated by .NET?

    please help/

    Lars
     
    Lars Netzel, Apr 7, 2005
    #1
    1. Advertising

  2. Hi Lars,

    the Button should write it's onclick attribute later (definitively after
    Load). Look at the html-output; what does asp.net write out for the "onlick"
    method of the specific button?

    But it's generally a good idea to append new methods to the onclick
    attributes. Check if myObj.Attributes ["onclick"] is set to an instance and
    then append the new method to the string.

    Hope that helps
    Patrick


    "Lars Netzel" wrote:

    > I have a simple aspx form where a few fields are validated with
    > RequiredFieledValidators. They work fine..
    >
    > Now I needed to add an own onclick validation that checks something else and
    > that has a errormessage that shoudl popup but it seems like I'm overwriting
    > the onclick generated by .NET and the validations are not happening.
    >
    > I add the onclick as the last row in Page_Load
    > btnSave.Attributes.Add("onclick", "javascript:return CheckInactive('" &
    > Lang.GetText("customer_inactivewarning") & "');")
    >
    > I'm thinking I need to add this at a different time to NOT overwrite the
    > onclick generated by .NET?
    >
    > please help/
    >
    > Lars
    >
    >
    >
    >
    >
     
    =?Utf-8?B?UGF0cmljaw==?=, Apr 7, 2005
    #2
    1. Advertising

  3. Lars Netzel

    Brock Allen Guest

    Well, this approach should work, but I'd try to go with a <asp:CustomValidator>.
    Does that not do what you need?

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > I have a simple aspx form where a few fields are validated with
    > RequiredFieledValidators. They work fine..
    >
    > Now I needed to add an own onclick validation that checks something
    > else and that has a errormessage that shoudl popup but it seems like
    > I'm overwriting the onclick generated by .NET and the validations are
    > not happening.
    >
    > I add the onclick as the last row in Page_Load
    > btnSave.Attributes.Add("onclick", "javascript:return CheckInactive('"
    > & Lang.GetText("customer_inactivewarning") & "');")
    >
    > I'm thinking I need to add this at a different time to NOT overwrite
    > the onclick generated by .NET?
    >
    > please help/
    >
    > Lars
    >
     
    Brock Allen, Apr 7, 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. DC Gringo

    2 onlick events?

    DC Gringo, Nov 2, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    489
    gh0st54
    Nov 2, 2004
  2. DC Gringo

    2 onlick events?

    DC Gringo, Nov 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    144
    gh0st54
    Nov 2, 2004
  3. Mike Dershowitz

    mixing onlick functions in link_to_function

    Mike Dershowitz, Jun 2, 2007, in forum: Ruby
    Replies:
    2
    Views:
    109
    Rob Biedenharn
    Jun 2, 2007
  4. Terje

    onlick insert date

    Terje, Nov 17, 2004, in forum: Javascript
    Replies:
    4
    Views:
    98
    Terje
    Nov 17, 2004
  5. Cylix
    Replies:
    3
    Views:
    93
    Ian Collins
    Apr 3, 2007
Loading...

Share This Page