Loading ...

Server Side Validation on a particular Button Click | CodeAsp.Net

Server Side Validation on a particular Button Click

0 (0votes)

In ASP.NET there is a server side validation which is very powerful and easy to use for developers and automatically validates the user input. Beginner developer facing problem when they validate a particular section of the page and page has more than one button in this case they are facing problem.
suppose we have a registration page there is two button one for Save and another for Cancel and we want validation only on Save button in this case we face the problem how to restrict validation on the cancel button and it is only working on Save button.

The solution of this problem is to use the CausesValidation Property of button control set false.

<asp:Button Id="btnCancel"runat="server" Text="Cancel"CausesValidation="False"></asp:Button>

Another way is to use the ValidationGroup property.


<asp:TextBox ID="txtBlogName" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvtxtBlogName" runat="server" ControlToValidate="txtBlogName" ValidationGroup="SaveUpdate">
<asp:Button Id="btnSave" runat="server"Text="Save" ValidationGroup="SaveUpdate"></asp:Button>

ValidationGroup property is used on Save button where we want to Validate the User Input i.e. ValidationGroup is used on that button on which button we want validation after that CausesValidation Property is not required on the Cancel button. if we did not use the ValidationGroup any of Server Validators then that user input field is not validate. so this is require, that every server validation control which is used on the page is contains the ValidationGroup property.
Hope this will be helpful....

Comments (no comments yet)

Top Posts