problem adding onlick attribute to Button from CodeBehind

L

Lars Netzel

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
 
G

Guest

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
 
B

Brock Allen

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top