469,602 Members | 1,769 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,602 developers. It's quick & easy.

Problem with validation controls

Hi,

I have the following code in my aspx page

<form id="Form1" method="post" runat="server">
<asp:TextBox ID="txtTest" Runat="server" />
<asp:RequiredFieldValidator ID="valText" ControlToValidate="txtTest"
Runat="server" Text="*" Display="Dynamic" ErrorMessage="Enter Value" />
<asp:ValidationSummary DisplayMode="BulletList" Runat="server"/>
<asp:Button Text="Submit" ID="Submit" Runat="server"/>
</form>

<script language="javascript">
<!--
function ValidateForm(targetForm)
{
return(confirm('Are you sure?'));
}
-->
</script>

In the code behind fiel for the aspx page, i have the following code (to
invoke the "ValidateForm" javascript function when the button is clicked)

this.Submit.Attrbutes.Add("onclick", "javascript:return
ValidateForm(this.form);");

I have NOT turned off client side validation / scripting.

Now, when I run the page and click on the submit button, the
ValidationSummary control is updated only after the form is posted to the
server - it does not happen at the client side (I can see the form is
posted). But, if i remove the javascript funtion call from the Submit button
(by removing the "this.Submit.Attrbutes.Add.." call from the code behind
file, the ValidationSummary control gets updated without making a trip to
the server.
How do I make the ValidationSummary control display the error message(s)
without making a trip to the server when the button has a javascript
function tied to it's client side onclick event handler? Any help will be
greatly appreciated.

CGUY
Nov 17 '05 #1
1 1716
Found out the solution myself. Though I would post it so that it benefits
someone....

Solution - modify the client side javascript function to the following

<script language="javascript">
<!--
function ValidateForm(targetForm)
{
if(Page_ClientValidate())
{
return(confirm('Are you sure?'));
}
}
-->
</script>

The Page_ClientValidate is a javascript validation API that will validate
all the (active) enabled validators in the page - so calling this function
in the above javascript function will result in the validators being
validated and the ValidationSummary control updated.

regards
CGUY

"CGuy" <cg**@csharp.net> wrote in message
news:uM**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have the following code in my aspx page

<form id="Form1" method="post" runat="server">
<asp:TextBox ID="txtTest" Runat="server" />
<asp:RequiredFieldValidator ID="valText" ControlToValidate="txtTest"
Runat="server" Text="*" Display="Dynamic" ErrorMessage="Enter Value" />
<asp:ValidationSummary DisplayMode="BulletList" Runat="server"/>
<asp:Button Text="Submit" ID="Submit" Runat="server"/>
</form>

<script language="javascript">
<!--
function ValidateForm(targetForm)
{
return(confirm('Are you sure?'));
}
-->
</script>

In the code behind fiel for the aspx page, i have the following code (to
invoke the "ValidateForm" javascript function when the button is clicked)

this.Submit.Attrbutes.Add("onclick", "javascript:return
ValidateForm(this.form);");

I have NOT turned off client side validation / scripting.

Now, when I run the page and click on the submit button, the
ValidationSummary control is updated only after the form is posted to the
server - it does not happen at the client side (I can see the form is
posted). But, if i remove the javascript funtion call from the Submit button (by removing the "this.Submit.Attrbutes.Add.." call from the code behind
file, the ValidationSummary control gets updated without making a trip to
the server.
How do I make the ValidationSummary control display the error message(s)
without making a trip to the server when the button has a javascript
function tied to it's client side onclick event handler? Any help will be
greatly appreciated.

CGUY

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Steve | last post: by
reply views Thread by Chris Nunciato | last post: by
reply views Thread by Dan | last post: by
3 posts views Thread by john morales | last post: by
6 posts views Thread by charliewest | last post: by
5 posts views Thread by Tina | last post: by
2 posts views Thread by Tim Frawley | last post: by
1 post views Thread by =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post: by
reply views Thread by =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post: by
5 posts views Thread by Kuldeep | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.