Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problem adding onlick attribute to Button from CodeBehind

Reply
Thread Tools

problem adding onlick attribute to Button from CodeBehind

 
 
Lars Netzel
Guest
Posts: n/a
 
      04-07-2005
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




 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF0cmljaw==?=
Guest
Posts: n/a
 
      04-07-2005
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
>
>
>
>
>

 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      04-07-2005
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
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mixing onlick functions in link_to_function Mike Dershowitz Ruby 2 06-02-2007 09:38 PM
how to implement onlick event on a node? Cylix Javascript 3 04-03-2007 11:23 AM
onlick insert date Terje Javascript 4 11-17-2004 07:50 PM
2 onlick events? DC Gringo ASP .Net 4 11-02-2004 11:58 PM
2 onlick events? DC Gringo ASP .Net Building Controls 4 11-02-2004 11:58 PM



Advertisments