473,386 Members | 1,705 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.

How to check from onclick if RequiredFieldValidator failed?

Hi,

I have a OnClientClick script assigned to a button. From the script, I'd
like to check if RequiredFieldValidator 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 4940
Hi Bogdan,

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

<head runat="server">
<title>Untitled 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:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"

ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return ConfirmSave();" UseSubmitBehavior="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 RequiredFieldValidator 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****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hi Bogdan,

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

<head runat="server">
<title>Untitled 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:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"

ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return ConfirmSave();" UseSubmitBehavior="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 RequiredFieldValidator 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****@discussions.microsoft.comwrote in message
news:9A**********************************@microsof t.com...
Hi Bogdan,

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

<head runat="server">
<title>Untitled 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:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"

ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
<asp:Button ID="Button1" runat="server" Text="Button"
OnClientClick="return ConfirmSave();" UseSubmitBehavior="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 RequiredFieldValidator 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
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. ...
3
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 ...
2
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 ...
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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
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...
0
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,...
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.