0

I have used Asp.net validation controls like Required Field Validator etc so do i need to explicitly mention Page.IsValid or is it called by default ?

<label>DeadLine</label>
<asp:TextBox ID="txtDeadLine" runat="server" CssClass="textField_width"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
                        ControlToValidate="txtDeadLine" ErrorMessage="Deadline Date is Required" 
                        ForeColor="Red" ValidationGroup="GroupComposeLetter">Deadline Date is Required
</asp:RequiredFieldValidator>
<br />
 <%--<asp:GridView ID="gridViewComplaints" runat="server"

     ></asp:GridView>--%>
<br />

user3518032
  • 423
  • 8
  • 25

2 Answers2

3

If the control has CausesValidation set to true (default) it is not needed.

Controls where this is set by default:

  • Button,
  • ImageButton,
  • LinkButton
  • Web server controls,
  • HtmlInputButton,
  • HtmlInputImage,
  • HtmlButton
  • HTML server controls,
  • controls that can automatically post back to the server such as the TextBox, CheckBox, ListControl, and BulletedList

So if you've set it to false you could force validation on serverside by calling Page.Validate(ValidationGroupName) manually. Afterwards you can check Page.IsValid.

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
  • ok but quoting your last sentence, Why would someone do that ? disabling and then calling in server ? – user3518032 May 08 '14 at 11:37
  • @user3518032: sometimes you don't want to force validation on clientside always but under certain conditions that are known on serverside. Or you want to combine multiple validation-groups. – Tim Schmelter May 08 '14 at 11:38
0

Validation occurs after Page_Load, but before event handlers (See http://msdn.microsoft.com/en-us/library/ms178472(v=VS.100).aspx).


If your button does not cause validation, you must manually fire Page.Validate.

  • (Page.Validate method is fired automatically by controls that have the CausesValidation property set to true(Which is default value for Button control).

  • Page.IsValid property tells you whether the validation succeeded or not.)

    More details, please see this discussion

How does Page.IsValid work?

Community
  • 1
  • 1