problem adding onlick attribute to Button from CodeBehind

  • Thread starter Thread starter Lars Netzel
  • Start date Start date
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
 
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
 
Back
Top