473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problem adding onlick attribute to Button from CodeBehind

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


Nov 19 '05 #1
2 1885
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


Nov 19 '05 #2
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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Michelle | last post by:
I have a div that is initially empty. Clicking on a button will add some text boxes and other controls so the user can add additional records. In IE all works fine but in Netscape 7.0 when I add...
3
by: Epetruk | last post by:
Hi, I'm trying to design a simple web form, but I cannot get the code in the btnSubmit_ServerClick event to fire. What am I doing wrong? Here's the codebehind: using System; using...
5
by: Phil Townsend | last post by:
I need to add a button to a datagrid. I have tried using the ButtonColumn and have also tried adding a button to a templatecolumn > itemtemplate. Whatever I have tried doesn't work, nor does it...
2
by: Herve MAILLARD | last post by:
Hi, J'ai un bouton ASPX qui doit déclencher un script java. I have an ASPX button running a javascript. To do this, I have added in the codebehind :...
3
by: Binod Nair | last post by:
Hi All, Can somebody tell me what I am doing wrong. I have a Base Abstract Class Public MustInherit Class BaseRequestHandler : Inherits System.Web.UI.Page Protected Overridable Sub...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
12
by: Wardeaux | last post by:
All, Wanting to find a way to create web pages to add to my website without having to recompile the codebehind everytime I want to add a new one... Here's the deal: I have a web app that takes...
6
by: Pete Davis | last post by:
I'm fairly weak with ASP.NET. What I'm trying to do is pass an attribute to a UserControl. The attribute is a value from the CodeBehind for the page. So in my .aspx I have the following: ...
3
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.