473,804 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to check from onclick if RequiredFieldVa lidator failed?

Hi,

I have a OnClientClick script assigned to a button. From the script, I'd
like to check if RequiredFieldVa lidator attached to a textbox on the page
has failed. The Page_IsValid works fine with - for example - regex
validator but it does not work with the required field validator.

Any suggestions will be appreciated.
Thanks,
Bogdan
Jun 27 '08 #1
3 4986
Hi Bogdan,

Please try the code below to check if page is valid or not in client side
script.

<head runat="server">
<title>Untitl ed Page</title>
<script type="text/javascript">
function ConfirmSave()
{
if (Page_IsValid )
{
return confirm('want to continue?');
}
else
{
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ControlToValida te="TextBox1"

ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick=" return ConfirmSave();" UseSubmitBehavi or="False"/></div>
</form>
</body>

Regards,
Manish

"Bogdan" wrote:
Hi,

I have a OnClientClick script assigned to a button. From the script, I'd
like to check if RequiredFieldVa lidator attached to a textbox on the page
has failed. The Page_IsValid works fine with - for example - regex
validator but it does not work with the required field validator.

Any suggestions will be appreciated.
Thanks,
Bogdan
Jun 27 '08 #2
Manish,

Thanks for the reply. Unfortunately this does not work for me. It actually
illustrates the problem that I've been having - i.e. Page_IsValid is true
even when the text box is empty. So, regardless of the content of the text
box I always get the 'want to continue?' message box.

Does this example behaves differently on your system? If yes, what browser
and asp version do you use?
I tested it in IE, FireFox, and Safari with asp 2.0 on the server.

Thanks again,
Bogdan

"Manish" <Ma****@discuss ions.microsoft. comwrote in message
news:9A******** *************** ***********@mic rosoft.com...
Hi Bogdan,

Please try the code below to check if page is valid or not in client side
script.

<head runat="server">
<title>Untitl ed Page</title>
<script type="text/javascript">
function ConfirmSave()
{
if (Page_IsValid )
{
return confirm('want to continue?');
}
else
{
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ControlToValida te="TextBox1"

ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick=" return ConfirmSave();" UseSubmitBehavi or="False"/></div>
</form>
</body>

Regards,
Manish

"Bogdan" wrote:
>Hi,

I have a OnClientClick script assigned to a button. From the script, I'd
like to check if RequiredFieldVa lidator attached to a textbox on the page
has failed. The Page_IsValid works fine with - for example - regex
validator but it does not work with the required field validator.

Any suggestions will be appreciated.
Thanks,
Bogdan

Jun 27 '08 #3
Hi Bogdan.
I have the same problem. I got around it by initializing Page_IsValid to
false on the page. It is maybe not the best and cleanest solution but as far
as I can see it works.

"Bogdan" wrote:
Manish,

Thanks for the reply. Unfortunately this does not work for me. It actually
illustrates the problem that I've been having - i.e. Page_IsValid is true
even when the text box is empty. So, regardless of the content of the text
box I always get the 'want to continue?' message box.

Does this example behaves differently on your system? If yes, what browser
and asp version do you use?
I tested it in IE, FireFox, and Safari with asp 2.0 on the server.

Thanks again,
Bogdan

"Manish" <Ma****@discuss ions.microsoft. comwrote in message
news:9A******** *************** ***********@mic rosoft.com...
Hi Bogdan,

Please try the code below to check if page is valid or not in client side
script.

<head runat="server">
<title>Untitl ed Page</title>
<script type="text/javascript">
function ConfirmSave()
{
if (Page_IsValid )
{
return confirm('want to continue?');
}
else
{
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator ID="RequiredFie ldValidator1"
runat="server" ControlToValida te="TextBox1"

ErrorMessage="R equiredFieldVal idator"></asp:RequiredFie ldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick=" return ConfirmSave();" UseSubmitBehavi or="False"/></div>
</form>
</body>

Regards,
Manish

"Bogdan" wrote:
Hi,

I have a OnClientClick script assigned to a button. From the script, I'd
like to check if RequiredFieldVa lidator attached to a textbox on the page
has failed. The Page_IsValid works fine with - for example - regex
validator but it does not work with the required field validator.

Any suggestions will be appreciated.
Thanks,
Bogdan


Aug 1 '08 #4

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

Similar topics

2
13278
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. I went ahead and wrote my own bit of code so I'm sharing it here for everyone. Even though it doesn't really disable the button by greying it out, it prevents the multiple submissions which it what I was attempting to prevent all along. ...
3
2183
by: Glenn | last post by:
I've got a datalist that includes in each databound row a button to delete that specific record. But for some reason, clicking the button does not trigger the event handler. here's the datalist <form runat="server"><asp:Label id="lblErrorText" runat="server" cssclass="FormValidationErrorText" enableviewstate="False"></asp:Label><asp:Label id="lblAgreementNbr" runat="server" enableviewstate="False"></asp:Label><br /><br /><br /><asp:datalist...
2
2700
by: Lasse Edsvik | last post by:
Hello Im using VS.NET and cant get this simple page to work.......... I get: CS0122: 'dbtest.WebForm2.Button1_Click(object, System.EventArgs)' is inaccessible due to its protection level what's wrong, i clicked the Button1 on designform and it created that onclick event.........
2
2101
by: Hongbo | last post by:
Hi, I have a Asp.Net written in C#. It serve as information input form. The form encounters sort of random problem with the email field and state field. I have validator attached with these 2 fields as the following: ===== <form id="creditcardform" method="post" runat="server"> Email: <asp:textbox id="txtBillEmail" maxlength="50" width="200" runat="server" /> <asp:requiredfieldvalidator id="vp10" runat="server" initialvalue="" ...
0
9714
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
10600
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
10350
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
10351
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
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
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...
0
6866
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4311
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
3834
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.