Validation Summary in ASP.NET

Posted by .Netlearner under ASP.NET on 8/14/2012 | Points: 10 | Views : 4389 | Status : [Member] | Replies : 3
Hello all,
Instead of displaying Each Seperate Regular Expression Validator Can we display The Error messages in validation summary.How this can be done




Responses

Posted by: Ranjeet_8 on: 8/14/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try this

<asp:TextBox ID="txtName" runat="server" MaxLength="80" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
ControlToValidate="txtName"
runat="server" ErrorMessage="Enter your name" Display="None"
SetFocusOnError="true">
</asp:RequiredFieldValidator>

<asp:TextBox ID="txtEmailID" runat="server" MaxLength="100" ></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2"
ControlToValidate="txtEmailID"
runat="server" ErrorMessage="Enter your email id" Display="None"
SetFocusOnError="true">
</asp:RequiredFieldValidator>




<asp:ValidationSummary ID="ValidationSummary1" runat="server" ShowMessageBox="true"
ShowSummary="false" />

OR
Refer this url
http://www.dotnetfunda.com/codes/code3016-how-to-use-validation-summary.aspx

.

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: San.Pblr.Gct on: 8/14/2012 [Member] Starter | Points: 25

Up
0
Down
If you already have individual validations, set Text of validationcontrol="*"

Like this

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  

<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="TextBox1"
ErrorMessage='Input Country!'
EnableClientScript="true"
SetFocusOnError="true"
Text="*"
>
</asp:RequiredFieldValidator>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator2"
runat="server"
ControlToValidate="TextBox2"
ErrorMessage='Input Region!'
EnableClientScript="true"
SetFocusOnError="true"
Text="*"
>
</asp:RequiredFieldValidator>


Then add validationsummarycontrol.

  <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Following error occurs:" ShowMessageBox="false" DisplayMode="BulletList" ShowSummary="true" />  


.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Srilu.Nayini577 on: 8/14/2012 [Member] Starter | Points: 25

Up
0
Down
we can write both above two codes.It works fine.
So you can use any of the above two approaches.

Thank you,

SRILATHA
.Net Developer

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response