473,715 Members | 6,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

custom client-side onClick events for asp:button

Hi, I'm writing an asp app. I have a text box with a validator and a
submit button. Here is code from my .aspx file....
<asp:TextBox ID="txName" TextMode="Singl eLine" Runat="server" />
<asp:RequiredFi eldValidator ID="vName" Runat=server
ControlToValida te="txName" />
<asp:Button ID="btnSave" CssClass="butto n" Runat="server" />
I wanted to have a javascript box pop up and ask the user if they're
sure they want to continue, so I added this script:
<script langauge=javasc ript>
function checkClick()
{
return confirm("are you sure...");
}
</script>

to call this onClick, I couldn't add it directly into the asp:Button,
so I added it in the codebehind file (.vb):

btnSave.Attribu tes("onClick")= "return checkClick();"

----
The only problem with this is that, in the resulting HTML,
checkClick() is called before the client-side validation, so if I
click ok, the submit goes through even if the txName required field is
blank... i.e. the client-side validators are never called (ASP adds
the Page_ClientVali date() call after my checkClick() call).

As a result, I need to check Page.IsValid on the server side. That's
ok (and I have to do it anyway for Netscape browsers), but it would be
nice to have the client-side validation and my javascript confirm()
message coexist.

Any suggestions?
thanks,
Frank
Nov 18 '05 #1
2 2118
Hi Frank,
This is what you need :)
http://www.dotnetjohn.com/articles/articleid39.aspx

Hope that helps
Have a great day :)
R. Pooran Prasad
Itreya Technologies Pvt Ltd.,
Mail: po***********@i treya.com.REMOVETHIS
Phone(Off) : +91 80 5200179 Extn: 42
Mobile: +91 98860 29578
-----Original Message-----
Hi, I'm writing an asp app. I have a text box with a validator and asubmit button. Here is code from my .aspx file....
<asp:TextBox ID="txName" TextMode="Singl eLine" Runat="server" /><asp:RequiredF ieldValidator ID="vName" Runat=server
ControlToValid ate="txName" />
<asp:Button ID="btnSave" CssClass="butto n" Runat="server" />
I wanted to have a javascript box pop up and ask the user if they'resure they want to continue, so I added this script:
<script langauge=javasc ript>
function checkClick()
{
return confirm("are you sure...");
}
</script>

to call this onClick, I couldn't add it directly into the asp:Button,so I added it in the codebehind file (.vb):

btnSave.Attrib utes("onClick") = "return checkClick();"

----
The only problem with this is that, in the resulting HTML,
checkClick() is called before the client-side validation, so if Iclick ok, the submit goes through even if the txName required field isblank... i.e. the client-side validators are never called (ASP addsthe Page_ClientVali date() call after my checkClick() call).

As a result, I need to check Page.IsValid on the server side. That'sok (and I have to do it anyway for Netscape browsers), but it would benice to have the client-side validation and my javascript confirm()message coexist.

Any suggestions?
thanks,
Frank
.

Nov 18 '05 #2
Just replace your <asp:button> with an <input type="button"
onclick="checkC lick()">. Then, have your checkClick() function call the
validator: if (Page_ClientVal idate()) { document.form.s ubmit(); }

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"giant food" <di**********@y ahoo.com> wrote in message
news:a6******** *************** ***@posting.goo gle.com...
Hi, I'm writing an asp app. I have a text box with a validator and a
submit button. Here is code from my .aspx file....
<asp:TextBox ID="txName" TextMode="Singl eLine" Runat="server" />
<asp:RequiredFi eldValidator ID="vName" Runat=server
ControlToValida te="txName" />
<asp:Button ID="btnSave" CssClass="butto n" Runat="server" />
I wanted to have a javascript box pop up and ask the user if they're
sure they want to continue, so I added this script:
<script langauge=javasc ript>
function checkClick()
{
return confirm("are you sure...");
}
</script>

to call this onClick, I couldn't add it directly into the asp:Button,
so I added it in the codebehind file (.vb):

btnSave.Attribu tes("onClick")= "return checkClick();"

----
The only problem with this is that, in the resulting HTML,
checkClick() is called before the client-side validation, so if I
click ok, the submit goes through even if the txName required field is
blank... i.e. the client-side validators are never called (ASP adds
the Page_ClientVali date() call after my checkClick() call).

As a result, I need to check Page.IsValid on the server side. That's
ok (and I have to do it anyway for Netscape browsers), but it would be
nice to have the client-side validation and my javascript confirm()
message coexist.

Any suggestions?
thanks,
Frank

Nov 18 '05 #3

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

Similar topics

3
7540
by: Lo?c Mah? | last post by:
Hello I try to use a Validator for a TxtCtrl placed in a Panel with a Button in order to trigger the Validator and test the content of TxtCtrl. I have looked into wxPython documentation and demo and searched in google, but I am still unsuccessful yet. My problem is that I do not manage to call the Validate() method of my Validator from the button handler.
0
1929
by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a button that prevents the user from submitting a form back multiple times and also prevents them from submitting the form and then clicking something else before the postback can finish processing. What I have is a working button that disables...
5
6730
by: Vern | last post by:
I'd like the default text to show up in designer, and allow it to be changed to something else. I was able to change some of the other properties, but for some reason I'm having trouble with the text. Here's the code from my latest attempt. I initially tried just setting this.Text = "E&xit" but that didn't work. Any ideas? public class ButtonExit : Button {
3
1304
by: Vern | last post by:
I have a custom button control that compares the user security level to the buttons security level property. If the user level is greater than the button level, then the button is enabled, else it is disabled. Now for the three questions: 1) I tried to retrieve the buttons security level property during the buttons constructor, but it can't get the actual value assigned to that button until sometime after the contructor finishes. Is...
3
1730
by: CroDude | last post by:
Hi all! I've made a button from scratch derived from a Control class. The main reason why Control and not Button class is used for inheritance is that when deriving from a control class it's possible to have a transparent background, while if derived from a button class it isn't. That's achieved through: SetStyle(ControlStyles.SupportsTransparentBackColor, true); But the problem appears when I place my buttons on a form and try to set...
3
7668
by: tshad | last post by:
Is there a way to use a custom button with the: <Input ID="MyFile" Type="File" RunAt="Server">? This gives you a generic button, but I would like to use my own button that has the same style as the other buttons I've created. Is there an easy way to do this? Thanks,
1
1700
by: Daniel Friend | last post by:
How do I add a custom button to the caption bar of a form like AOL does for it's favorites. Thanks, Dan
3
2408
by: Kannan | last post by:
I am creating Outlook Add-in Component using C#. I have created custom button "Formard mail" in outlook using C# component. This is displaying in Outlook menu bar. If user pressed this button, I want to save the selected mail in C: as a .msg file. Could you help me how to do that. Thanks in advance. Regards,
2
1506
by: Bill Steele | last post by:
Wanted a "mail this page" button to not look like a button. So this: <button class="emailArticleButton" onmouseover="this.className='emailArticleButtonChange';" onmouseout="this.className='emailArticleButton';" type="submit" name="submit"></button> The classes take you to a CSS file that makes the button the usual little image of an envelope.
7
9079
by: Marcolino | last post by:
Hi all, I need to add a custom button to title bar on a form in addition of a standard button. (Minimize/Maximize, close etc.) I need also to handle OnClick event of this button. I looked around google but i'm not able to find any example that can help me. Many thanks in advance for your help. Marco
0
8823
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9343
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9198
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9104
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3175
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2541
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.