• No results found

Customer Validator

In document ASP (Page 83-92)

Enter any text

5. Customer Validator

6. Validation Summary---displaying validation error messages

common properties for all validation controls:

• ControlToValidate =some control id

• Error Message=some text

• Display=static, dynamic none

• Is Valid=T/F

• Enabled Client Script=t/F

• Set focus on error (2.0): t/f I is used to focusing the control when it contains invalid value

• ValidationGroup(2.0):some text or group ID

• Required Field validator : used to check whether the the i/p control contains value or not and if the value is not existing it provides error message this control is used to check the emptiness of the control that we are validating

• If the control that we are validating doesn’t contain any value then required field validator will return false to the webpage

• If the control that we are validating contains any value then required field validator will return True to the webpage

• Control to validate: this property is used to set the name of the control that we are validating using req field validator

• Error Message: this property is used to set the req message that is to be displayed when req field validator returns false

• Extra property: initial value=some text

Example

Properties:

Design: drag and drop required field validator Properties of required field validator are

Control to Validate=TextBox1

Error Message=TextBox should contain some Text

• Extra properties:

• Maximum Value :this property is used to set the highest value with which we would like to compare the user entered data

• Minimum Value: this property is used to set the highest value with which we would like to compare the user entered data

• Type: this property is used to set the required datatype with which we would like to compare the user entered data

• Type=integer/string/double/date etc…….

example  

Properties:

Design: drag and drop range validator Properties of range validator are

Control to Validate=TextBox2 Error Message=invalid age

Minimum Value=18 Type=integer

• Compare validator: this control is used for comparing to controls or used for comparing a control with the value

• If both the controls contents are same then compare validator will return true otherwise false

• Properties:

• control to compare: this property is used to set the control name with which we want to compare the contents of the control that has been set in control to validate property

• Control to compare =some id

• Value to compare=some value

• Operator=equal, not equal,<,> etc…

• Type:string,Integer,double,Date etc…….

Example

Properties:

Go to toolbox drag and drop compare validator Control to validate=TextBox2

Control to compare =TextBox1 Operator=equal

Type: string,

like email id form or internet url address or phone no or in pin code format no

• If user entered data matches with the set format then reg expression validator will return true to the webpage otherwise false

• Properties:

• Control to validate:

• Error Message:

Properties:

Go to toolbox drag and drop Regular expression validator.

Validation expression=select internet url address

Validation Expression: this property is used to set the required expression f format with which we want to compare

• There are predefined expressions available to compare and also we can write our own expressions

• This control is used to perform the validations whenever existing validation controls donot make the user requirements

• This control is used to perform both client side and server side validations

• This is the only control in complete validation controls which is used to perform both client side and server side validations

• Properties

• Control to validate

• Client validation functions

• Error message

• Validation summary : it is used to display all the error messages in that webpage This control is not used to perform any validations rather it will display all other validation controls error messages as a group together

User name Required fiels validator

password Required fiels validator

Retype password Compare validator

Age  Range validator

Submit  Validation summary Example:

Drag and drop validation summary

• Client validation functions : this property is used to set the required java script function using we want to validate the required control data Example using custom validator to perform client side validations

• Properties

• Control to validate=textbox2.text

• Error message=passw ord should contain min of 6 characters

• Client validation functions =F1 Enter username

Enter password Custom validator

submit

Go to source part of the html page and write the JavaScript function code like

<head >

<script type="text/javascript">

function F1(X,Y) {

if(Y.Value.length>=6) {

Y.IsValid=true;

} else {

Y.IsValid=false;

}}

</script>

</head>

Button1_Click

{ Response.Redirect("page submitted");}

• To perform client side validations using custom validator control whatever the function we define the function should contain 2 args always

• 1st arg will store the type of the control from which function has been called

• 2nd arg contain 2 important properties

• Value

• IsValid

• Value: property stores the data entered by user in the control that we are validating

• IsValid:this is a boolean property stores True/false and will return either true or false to custom validator control when function execution is completed

• Example to perform server side validations using custom validator control

• In the above example we perform the validation to check password is

“kanna” or not

• If user enters password …………> kanna then we display a message as page submitted otherwise error message displayed

Enter username

Select custom validator …..> goto properties window…..>click on events button…..>double click on server validate event write the following code protected void Page_Load(object sender, EventArgs e)

{ }

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)

} }

protected void Button1_Click(object sender, EventArgs e) {

Navigation controls: these controls are used for fast navigation between the web page on a website

• Some of the navigation controls are

• MENU

• TREE VIEW

• SITEMAP PATH CONTROL

• These controls are introduced only in 2.0 which we have to develop using scripting languages or we have to download from Microsoft control gallery in the previous versions of Asp. Net

• MENU CONTROL:

• Properties:

• Disappear After=some millisecond

• Items=Root, adding root, adding child, removing item

• Items---text, navigate url,image url,value

• Dynamic menu style=some color Example :

Step1: go to toolbox drag and drop menu control Step2: select menu controls properties

Items=add root item----select new item---Text=HOME similarly

Add ABOUTUS,CONTACT US

Step3: select HOME navigate url=home.aspx select ABOUTUS navigate url=aboutus.aspx select CONTACTUS navigate url=contactus.asp

step4:add home.aspx aboutus.aspx contactus.aspx to the existing project

Step 5: Debug and check the output

TREE VIEW CONTROLS: This control is used for displaying some information in a branched tree structure format with expansion and collapsion

• It always display in a vertical manner and does not support different property for dynamic and static displaying

• Properties:

• Disappear After=some millisecond

• Nodes=Root, adding root, adding child, removing item

• Nodes--text, navigate url,image url,value

• Dynamic menu style=some color Example:

Step1: go to toolbox drag and drop treeview control Step2: select menu controls properties

Nodes=add root item----select new item---Text=HOME similarly

Add ABOUTUS,CONTACT US

Step3: select HOME navigate url=home.aspx select ABOUTUS navigate url=aboutus.aspx select CONTACTUS navigate url=contactus.asp

step4:add home.aspx aboutus.aspx contactus.aspx to the existing project

Example:

In document ASP (Page 83-92)

Related documents