Validation Controls: By: Dr. Deepak Mathur

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 49

By :

Dr. Deepak Mathur

VALIDATION CONTROLS89
Dr. Deepak Mathur LMCST (ASP.NET )

VALIDATION CONTROLS
 Need of Validation control

 Is it a control really ? If yes then which type of …….

 HTML Server controls vs Real Server Controls (ASP.Net)


controls

 Is it in above 2 categories or a third one

2
Dr. Deepak Mathur LMCST (ASP.NET )

VALIDATION CONTROLS
 Why needed ?

 Can Just writing one statement replace it .


Think about it……

 We were doing it in previous semester

 What was the problem then when we were doing it in previous


semesters

 Let us discusss the problem

3
Dr. Deepak Mathur LMCST (ASP.NET )

VALIDATION CONTROLS
 ASP.NET provides a third category of control known as
validation control.
 Examples:
 RequiredFieldValidator Control
 CompareValidator Control
 RangeValidator Control
 RegularExpressionValidator Control
 ValidationSummary Control
 CustomValidator Control

4
Dr. Deepak Mathur LMCST
(ASP.NET )

REQUIREDFIELDVALIDATOR CONTROL

5
Dr. Deepak Mathur LMCST (ASP.NET )

 Properties
 ID
 ControlToValidate
 Display
 ErrorMessage
 RunAt

6
Dr. Deepak Mathur LMCST (ASP.NET )

Display Property………………………

7
Dr. Deepak Mathur LMCST (ASP.NET )

8
Dr. Deepak Mathur LMCST (ASP.NET )

COMPAREVALIDATOR CONTROL

9
Dr. Deepak Mathur LMCST (ASP.NET )

 Properties
 ID
 ControlToValidate
 Display
 ErrorMessage
 RunAt
 ControlToCompare or ValueToCompare

10
Dr. Deepak Mathur LMCST (ASP.NET )

RANGEVALIDATOR CONTROL

11
Dr. Deepak Mathur LMCST (ASP.NET )

 Properties
 ID
 ControlToValidate
 Display
 ErrorMessage
 RunAt
 MaximumValue
 MinimumValue
 MaximumControl
 MinimumControl
 Type

12
Dr. Deepak Mathur LMCST (ASP.NET )

13
Dr. Deepak Mathur LMCST (ASP.NET )

REGULAREXPRESSIONVALIDATOR CONTROL

14
Dr. Deepak Mathur LMCST (ASP.NET )

 Properties
 ID
 ControlToValidate
 Display
 ErrorMessage
 RunAt
 ValidationExpression

15
Dr. Deepak Mathur LMCST (ASP.NET )

SYMBOLS USED IN VALIDATION EXPRESSION

[ ]
range of alphabets or digits
{ }
number of occurrence
/s
space
_
Dash is required
16
Dr. Deepak Mathur LMCST (ASP.NET )

17
Dr. Deepak Mathur LMCST (ASP.NET )

 [ a-z ]
 Means alphabets from a to z

 [ A-Z ]
 Means alphabets from A to Z

 [0-9]
 Means Digits from 0 to 9

18
Dr. Deepak Mathur LMCST (ASP.NET )

19
Dr. Deepak Mathur LMCST (ASP.NET )

VALIDATIONSUMMARY CONTROL

Properties
ID
RunAt
DisplayMode >list ,bulletedlist
HeaderText
ShowMessageBox > whether to display or not
ShowSummary

20
Dr. Deepak Mathur LMCST (ASP.NET )

21
Dr. Deepak Mathur LMCST (ASP.NET )

CUSTOMVALIDATOR CONTROL

 Properties
 ID
 ControlToValidate
 Display
 ErrorMessage
 RunAt
 ClientValidationFunction ??????????????

22
Dr. Deepak Mathur LMCST (ASP.NET )

23
Dr. Deepak Mathur LMCST (ASP.NET )

From where it has


come ???????????????????

24
Dr. Deepak Mathur LMCST (ASP.NET )

DYNAMIC CONTROLS
 What are these ?
 These are the controls that are not created at compile time.
 If not at compile time then at which time?
 the ans is at RUNTIME

 What is the necessity ???

25
Dr. Deepak Mathur LMCST (ASP.NET )

DYNAMIC CONTROLS
 Source Code
<script language="vb" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)

Dim lblMessage as New Label()


lblMessage.Text = "Hello, World!"
lblMessage.Font.Bold = True
Controls.Add(lblMessage)
End Sub
</script>

26
Dr. Deepak Mathur LMCST (ASP.NET )

 Errors
 CompileTime
 Semantic
 RunTime

The process of going through the code to identify the root


cause of an error in the application is called

Debugging
27
Dr. Deepak Mathur LMCST (ASP.NET )

ERROR HANDLING 115

 What happens if runtime error occurs??????


 An HTML error page is generated and displayed
in the browser. This page is not user friendly.
 IS IT ??????????????????????
 This page contians secure information, such as
the remote machine compiler messages,
configurationsettings, filenames, stack traces, or
source code and is revealed on the client

28
Dr. Deepak Mathur LMCST (ASP.NET )

 If we want this not to happen then there is a way by


using web.config file
 Following is a sample of the Web.config file that you
can modify:
 <configuration>
 <system.web>
 <customErrors mode="Off" />
 </system.web> ??????????
 </configuration>

29
Dr. Deepak Mathur LMCST (ASP.NET )

 The mode attribute of the <customErrors> tag can take three values:
 On: Indicates that the custom error messages are always sent to
users and that the detailed ASP.NET error page is never shown.
 Off: Indicates that only original error messages are sent to users
even if a custom error page is available.
 RemoteOnly: Indicates that the custom error messages are displayed
only to remote users accessing the site. If no custom error page is
available, remote users simply see a message indicating that an
error has occurred.

30
Dr. Deepak Mathur LMCST (ASP.NET )

 <customErrors mode="RemoteOnly"
defaultRedirect=“a.aspx"/>

So here not the html page generated by ASP.NET


would be shown but instead a.aspx would be
shown

31
Dr. Deepak Mathur LMCST (ASP.NET )

A.ASPX FILE

<html>
<body>
<b> Sorry for the error occurred. For further assistance
contact the System Administrator
Email : [email protected]
Mob : 1111111111
</b>
</body>
</html>
32
Dr. Deepak Mathur LMCST (ASP.NET )

 You can specify specific error messages, such as


"Page not found" or "server crash" for specific
status codes, as shown in the following code:

33
Dr. Deepak Mathur LMCST (ASP.NET )

<configuration>
<system.web>
<customErrors
defaultRedirect="http://host1/a.aspx" mode="RemoteOnly">
<error statusCode="500"
redirect="http://host1/pages/b.html"/>
<error statusCode="403"
redirect="http://host1/pages/c.html"/>
</customErrors>
</system.web>
</configuration

34
Dr. Deepak Mathur LMCST (ASP.NET )

USING DEBUGGING TOOLS


 There are 2 debugging tools available in
ASP.NET .
 These are :
 1. Using the Debug menu
 2.Tracing
 2.1 Page level
 2.2 Application level

35
Dr. Deepak Mathur LMCST (ASP.NET )

1. USING THE DEBUG MENU

36
Dr. Deepak Mathur LMCST (ASP.NET )

Step Out

37
Dr. Deepak Mathur LMCST (ASP.NET )

 Example on Next page

38
Dr. Deepak Mathur LMCST (ASP.NET )

Source of
Malfunctioning

39
Dr. Deepak Mathur LMCST (ASP.NET )

 Now to stop the debugging process, select


Debug -- Stop Debugging.
 Next, remove the breakpoint (Press F9 at the line
at which the breakpoint was set).

40
Dr. Deepak Mathur LMCST (ASP.NET )

2.TRACING

 In ASP.NET, the trace feature ensures that the


programmers are able to log their applications by
providing the means to monitor and examine
program performance either during evelopment or
after deployment. ASP.NET allows tracing at two
levels:
Page-level tracing
Application-level tracing
TraceContext class -???????????
41
Dr. Deepak Mathur LMCST (ASP.NET )

TRACECONTEXT CLASS
 Properties of the TraceContext class
 1.IsEnable

 2.TraceMode

 2.1 Alphabetically

 2.2 By time< as they appear in their


order>

42
Dr. Deepak Mathur LMCST (ASP.NET )

PUBLIC INSTANCE METHODS OF THE TRACECONTEXT CLASS

43
Dr. Deepak Mathur LMCST (ASP.NET )

PAGE-LEVEL TRACING

Has to be made
True

44
Dr. Deepak Mathur LMCST (ASP.NET )

OUTPUT OF PAGE LEVEL TRACING

45
Dr. Deepak Mathur LMCST (ASP.NET )

APPLICATION-LEVEL TRACING
 Application-level Tracing is enabled by using the Web.config file.
 Here is the web.config file code:

<configuration>
<system.web>
<trace
enabled="true"
requestlimit="10"
pageoutput="false"
tracemode="SortByTime"
/>
</system.web>
</configuration>

46
Dr. Deepak Mathur LMCST (ASP.NET )

APPLICATION-LEVEL TRACING
 Attributes of the Trace element
 1. enabled
 2. requestlimit
 3. pageoutput
 3.1 true
 3.2 false
 4. tracemode
 4.1 sorted by time
 4.2 sorted by category

47
Dr. Deepak Mathur LMCST (ASP.NET )

OUTPUT OF APPLICATION LEVEL TRACING

48
Dr. Deepak Mathur LMCST (ASP.NET )

 THANK YOU
 UNIT 3 ENDS

49

You might also like