Problem with validation controls

C

CGuy

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
 
C

CGuy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top