473,378 Members | 1,397 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,378 software developers and data experts.

Modify the builtin onclick event of button?

When add a button to a web form, if the button can CauseValidation, the
server emits client side javascript as:
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); "
language="javascript" id="Button1" />

What I want to let the emitted javascript like :
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate();
if (Page_IsValid !=null && Page_IsValid == true)
DoSomethingIWant();"
language="javascript" id="Button1" />

If I override the Render() method, the buildin jscript always emitted. How
can I get the exactly I want above?

Thanks in advance.
Nov 19 '05 #1
2 2957
You can add an onclick event handler to the button like this:

Button1.Attributes.Add("onclick", "if (Page_IsValid !=null && Page_IsValid
== true) DoSomethingIWant();");

"Caspy" <ca******@yahoo.com> wrote in message
news:eH**************@TK2MSFTNGP15.phx.gbl...
When add a button to a web form, if the button can CauseValidation, the
server emits client side javascript as:
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); "
language="javascript" id="Button1" />

What I want to let the emitted javascript like :
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate();
if (Page_IsValid !=null && Page_IsValid == true)
DoSomethingIWant();"
language="javascript" id="Button1" />

If I override the Render() method, the buildin jscript always emitted. How
can I get the exactly I want above?

Thanks in advance.

Nov 19 '05 #2
You approach generates something like:
<input type="submit" name="Button1" value="Button" onclick="if(Page_IsValid
== fasle) alert('Invalid!');if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); " language="javascript" id="Button1" />

The key point here is that (Page_IsValid == fasle) is checked before the
page is validated, which the Page_IsValid always true. This is not waht I
want.
"Raul Macias" <ra*********@hotmail.com> wrote in message
news:u3**************@TK2MSFTNGP12.phx.gbl...
You can add an onclick event handler to the button like this:

Button1.Attributes.Add("onclick", "if (Page_IsValid !=null && Page_IsValid
== true) DoSomethingIWant();");

"Caspy" <ca******@yahoo.com> wrote in message
news:eH**************@TK2MSFTNGP15.phx.gbl...
When add a button to a web form, if the button can CauseValidation, the
server emits client side javascript as:
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate(); "
language="javascript" id="Button1" />

What I want to let the emitted javascript like :
<input type="submit" name="Button1" value="Button"
onclick="if (typeof(Page_ClientValidate) == 'function')
Page_ClientValidate();
if (Page_IsValid !=null && Page_IsValid == true)
DoSomethingIWant();"
language="javascript" id="Button1" />

If I override the Render() method, the buildin jscript always emitted.
How can I get the exactly I want above?

Thanks in advance.


Nov 19 '05 #3

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

Similar topics

2
by: Vinita Sharma | last post by:
Hi All, I have a strange problem. I have 2 text boxes and a button in my form. There is a function called on onchange event of the first text box. There is another function called on onclick...
2
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } ...
3
by: f1crazed | last post by:
Hello, I am wanting to fire the onClick event of button1 by pressing button2. Does anyone have a clue if this is even posible? If so PLEASE HELP!! Thanks.
2
by: jdph40 | last post by:
In Access 97, I have a form named frmEmpList with a list box that contains the names of all our employees. I have a command button with the following code in the OnClick event so the form will...
5
by: moondaddy | last post by:
I have a <a> element in a datagrid which wraps some asp.net labels. this element also has an onclick event which does not fire in netscape 6 (and perhaps other browsers for all I know...). Below...
5
by: kai | last post by:
Hi, In ASP.NET , what is the difference between OnClick and Click events for a button? Because we have button click event, it can trigger events, why we still need OnClick? Please help. ...
7
by: extremerep | last post by:
My task is to change the value of a button and then make it functional with the onClick handler. Changing the value to "Play Again" works, but making the onClick work accordingly does not. The...
5
by: Stuart Shay | last post by:
Hello All I am working on ASP.NET 1.1 Custom Pager that allows a User to Enter a Number in a TextBox and go to the page selected. Since the OnClick Event does not work in ASP.NET 1.1 for a...
3
by: Michael_R_Banks | last post by:
I'm trying to dynamically build a table that allows users to remove rows when they click a corresponding button. For some reason, whenever I add the button to the table, it never fires the onclick...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.