Validation Group

S

sck10

Hello,

I have a button that is associated with a validation group. When I click
the button and a validation fails, I still want to code to execute. Can
this be done? Any help with this would be appreciate.

Thanks in advance, Sck10

In my code behind:
Sub Submit_Click(ByVal Sender As Object, ByVal Args As EventArgs)
lblRegisterMsg.Text = "<hr />Page.IsValid:" & Page.IsValid.ToString() &
"<br />"
End Sub


Snippet of content page:

<!-- Test Validation Stuff -->
<asp:Label id="lblRegisterMsg" runat="server" />
<asp:ValidationSummary
ValidationGroup="vgDocUpload"
id="valSummaryMessage"
HeaderText="<hr />The following errors were found:"
runat="server" />


<tr>
<td width="100"><div align="right">Submitter:</div></td>
<td width="500"><div align="left">
<asp:textbox id="txtSubmitter" Runat="server"/>
<asp:RequiredFieldValidator ID="rfvSubmitter"
ValidationGroup="vgDocUpload"
ControlToValidate="txtSubmitter"
ErrorMessage="Your name is missing."
Text="*"
Runat="server" />
</div></td>
</tr>

<tr>
<td width="100"><div align="right">Select File:</div></td>
<td width="500"><div align="left">
<asp:Button ID="btnUpload"
ValidationGroup="vgDocUpload"
Text="Upload"
OnClick="Submit_Click"
Runat="server"/>
</div></td>
</tr>
 
S

Steven Cheng[MSFT]

Hi Sck10,

From your description, you're using the Validation Controls on a webform to
validate some entry fields. And when we push a submit button, the validtion
will occur which prevent the form be posted back, so you're wondering how
to make the post back still occur when there is validation error , yes?

Based on my understanding, this problem is caused by the validation
controls' clientside validtion which will prevent the form from being
submit. If you still want the form be posted back( and button's event
handler be executed), we can choose either of the following means:
1. Turn off the validation control's EnableClientScript propety (set to
false) , then the client validation won't take place. But still let the
submit button as "CauseValidation" = true ( this is the default settting).
Thus, when we push the submit button, the form will be posted back to
serverside and validtion is done before button's postback eventhandler
(after Page_Load).

2. Set the Submit's CauseValidation to "false" , then the validation won't
take place automaticaly when we hit the submit button. But we can manually
call the Page.Validate() in the Page_Load method to manually make the page
to validating all the controls which is attached with a validtor. Also in
the Button's Click Event , the Page.IsValid is accessable after the
validtion.

And here is a tech article discussing on the underlying detail of ASP.NET's
validation (client and serverside):

#ASP.NET Validation in Depth
http://msdn.microsoft.com/library/en-us/dnaspp/html/aspplusvalid.asp?frame=t
rue#aspplusvalid_serverside

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top