1 / 15

Session 4

Session 4. Advanced. Validation Techniques. Session Objectives. Explore the various Validation Controls. Explain code behind. Implement code behind. Validation Controls. Restricts blank field. RequiredFieldValidator. CompareValidator. Compares two fields. Checks for specified range.

Download Presentation

Session 4

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Session 4 Advanced Validation Techniques Building Applications using ASP.NET and C# / Session 4 / 1 of 15

  2. Session Objectives • Explore the various Validation Controls • Explain code behind • Implement code behind Building Applications using ASP.NET and C# / Session 4 / 2 of 15

  3. Validation Controls Restricts blank field RequiredFieldValidator CompareValidator Compares two fields Checks for specified range RangeValidator Checks value with expression RegularExpressionValidator Checks value by client-side or server-side function CustomValidator ValidationSummary Lists validation errors of all controls on the page Building Applications using ASP.NET and C# / Session 4 / 3 of 15

  4. RequiredFieldValidator Inline error message No value is entered <asp:requiredfieldvalidatorcontroltovalidate="userid" display="static" errormessage="You must enter your user id." runat=server> The User Id cannot be left Blank! </asp:requiredfieldvalidator> Building Applications using ASP.NET and C# / Session 4 / 4 of 15

  5. Validation Error Message Dynamic Display Building Applications using ASP.NET and C# / Session 4 / 5 of 15

  6. CompareValidator <asp:comparevalidatorcontroltovalidate="pwd_con" display="static" errormessage="the confirmation password does not match." controltocompare="pwd" type="String" operator="Equal" runat=server> * </asp:comparevalidator> = , < , > , <= , >= , Not Equal String, Integer, DateTime, Currency, Double <asp:comparevalidatorcontroltovalidate="bid" display="static" errormessage="You cannot enter a bid for lesser than $100.“ valuetocompare=100 type="Integer" operator="GreaterThanEqual" runat="server">* </asp:comparevalidator> Comparing with static value, 100 Building Applications using ASP.NET and C# / Session 4 / 6 of 15

  7. RangeValidator <asp:rangevalidatorcontroltovalidate="r3" type="Integer" minimumvalue="1" maximumvalue="99" errormessage="Your age must be in the range of 1-99 yrs" display="static" runat="server" > * </asp:rangevalidator> Specify value of the control for the range Specify name of the control for the range <asp:rangevalidatorcontroltovalidate="r4" type="Integer" minimumcontrol="r1" maximumcontrol="r2" errormessage="Your age must be in the range of 1-99 yrs" display="static" runat="server" > * </asp:rangevalidator> Building Applications using ASP.NET and C# / Session 4 / 7 of 15

  8. Sign Meaning ^ The caret sign ^ specifies that checking starts from here $ The “$” sign specifies that the checking ends here [] Square brackets “[]” checks that the value entered match with any of the characters that are in the square brackets. \w “\w” allows any value to be entered /d{} “/d” specifies that the value entered is a digit and {} specifies the number of occurrences of the specified data type + The + sign indicates that one or more elements to be added to the expression being checked RegularExpressionValidator - 1 Building Applications using ASP.NET and C# / Session 4 / 8 of 15

  9. RegularExpressionValidator - 2 Validate an email id <asp:regularexpressionvalidatorcontroltovalidate="emailid" display="static" validationexpression="^[\w-]+@[\w-]+\.(com|net|org|edu|mil)$" runat=server> Not a valid e-mail address </asp:RegularExpressionValidator> Building Applications using ASP.NET and C# / Session 4 / 9 of 15

  10. CustomValidator Client-side function <asp:customvalidatorrunat="server" controltovalidate="grade" clientvalidationfunction="clval" onservervalidate="serval" display="static"> Wrong value </asp:customvalidator> Building Applications using ASP.NET and C# / Session 4 / 10 of 15

  11. ValidationSummary <asp:validationsummaryid="vs1" headertext="The errors found are: " displaymode="singleparagraph" runat="server"/> </asp:customvalidator> Building Applications using ASP.NET and C# / Session 4 / 11 of 15

  12. Page.IsValid Property <script language="C#" runat="server" > void validate_page(Object Src, EventArgs E){ if (Page.IsValid == true) { lbl.Text = "Page is Valid!";} else { lbl.Text = "Page is not Valid!"; } } </script> Building Applications using ASP.NET and C# / Session 4 / 12 of 15

  13. Uplevel and Downlevel Browsers Downlevel Uplevel Internet Explorer 4 < < = Browsers Browsers HTML 4 HTML 3.2 Client-side validation Server-side validation <%@ Page ClientTarget=DownLevel %> disable client-side validation Building Applications using ASP.NET and C# / Session 4 / 13 of 15

  14. Code Behind - 1 .aspx file Provides the functionality <%@ Page language="C#" Inherits="codeb" %> <html> <script language="C#" runat ="server" > </script> <form runat="server"> <asp:button OnClick="bMe_Click" text="Click me!" id="bMe" runat="server"/><br><br><br><br> <asp:label id="lb1" runat="server"/> </form> </html> Building Applications using ASP.NET and C# / Session 4 / 14 of 15

  15. Code Behind - 2 using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public class codeb: Page { public System.Web.UI.WebControls.Label lb1; public System.Web.UI.WebControls.Button bMe; protected void bMe_Click(Object sender, EventArgs e) { lb1.Text = "Clicked!"; } void Main() { } } .CS file BIN Seperated programming code Building Applications using ASP.NET and C# / Session 4 / 15 of 15

More Related