0% found this document useful (0 votes)
2 views

Asp.net unit-II

The document provides an overview of various validation controls in ASP.NET, including RequiredFieldValidator, RangeValidator, CompareValidator, RegularExpressionValidator, CustomValidator, and ValidationSummary. It explains the importance of form validation, detailing both client-side and server-side validation processes, and provides examples of how to implement these controls in web forms. Additionally, it covers the properties and syntax for each validation control, along with practical examples to illustrate their use.

Uploaded by

rogitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Asp.net unit-II

The document provides an overview of various validation controls in ASP.NET, including RequiredFieldValidator, RangeValidator, CompareValidator, RegularExpressionValidator, CustomValidator, and ValidationSummary. It explains the importance of form validation, detailing both client-side and server-side validation processes, and provides examples of how to implement these controls in web forms. Additionally, it covers the properties and syntax for each validation control, along with practical examples to illustrate their use.

Uploaded by

rogitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

22UCSCC62 : DOTNET PROGRAMMING

Unit II: Using validation controls


Overview of the validation controls – using the RequiredFieldvalidator,
RangeValidator, CompareValidator, CustomValidator, RegularExpressionValidator,
ValidationSummary - Using richcontrols : Accepting File Uploads – Displaying a
calendar displaying advertisements – displaying different page views.

Form Validation:
A web form has many input controls like TextBoxs. These controls should have right
type of data before submitting form at server side for data processing. Thus checking the
input controls called form validation.
Form validation includes-
1. Check control has required value.
2. Check value of control falls between minimum and maximum value.
3. Compare value of control against another value.
4. Check value of control is match with given format.
For example: If data is not input into TextBox then an error message should be display. It
is done using RequiredFieldValidator control.

Client side and server side Validation:


The validation of control can be performed at client side and server side.

1. Client side validation: When validation code is executed at client side by Browser
software called client side validation. Client side validation prevents form submission
to the server until all input values of control becomes error less. Validation code is
written / generated in JScript for client side validation. Client side validation saves
time for checking error that may consumes in between client to server and server to
client.

2. Server side validation: When validation code is executed at server side by any
programming language (C# / VB) called server side validation. Server side validation
happens after form submission to the server. At server side, values of controls are
checked. If any error founds then response to the client side using new web page.
This process consumes more time as compared to client side validation.

Validation Controls:
ASP.NET provides following set of validation controls that may validate value of form
control at client side (default) or server side.
1. RequiredFieldValidator
2. RangeValidator
3. CompareValidator
4. RegularExpressionValidator
5. CustomeValidator
N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 1
22UCSCC62 : DOTNET PROGRAMMING

ValidationSummaryThese validation controls can be apply on any control that has


decorated with ValidationProperty attribute.

RequiredFieldValidator control:

This validation control checks to required value is input or not into specified input control
before submitting the form. This control needs to link any one input control like TextBox.
Syntax:
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" />
Important Properties:
- ControlToValidate: ID of control to be validate.
- Text: text to display for the validator when the validated control is invalid.
- ErrorMessage: Message to display in a ValidationSummary when the
validated control is invalid.
- ToolTip: The tooltip displayed when the mouse is over the control.
- EnableClientScript: If it is true then validation is performed at client side by
browser otherwise performed at server side.

CauseValidation property of Button: If false then button does not causes validation to
fire.
Example:

<%@ Page Language="C#" %>


<html>
<head>
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div> Your
Name
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="TextBox1"

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 2


22UCSCC62 : DOTNET PROGRAMMING

ErrorMessage="Your Name is empty" ToolTip="Input


Your Name" Text="(Required)" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button2" runat="server" Text="Cancel" CausesValidation="False" />
</div>
</form>
</body>
</html>

RangeValidator control:

This validation control checks input value falls between a certain minimum and
maximum value. This control needs to link any one input control like TextBox.
Syntax:
<asp:RangeValidator ID="RangeValidator1" runat="server" />
Important Properties:
- ControlToValidate: ID of control to be validate.
- MinimumValue: The minimum value for the control being validated.
- MaximumValue: The maximum value for the control being validated.
- Type: Data type of values for comparison. (String / Integer / Double / Date /
Currency)
- Text: text to display for the validator when the validated control is invalid.
- ErrorMessage: Message to display in a ValidationSummary when the
validated control is invalid.
- ToolTip: The tooltip displayed when the mouse is over the control.
- EnableClientScript: If it is true then validation is performed at client side by
browser otherwise performed at server side.

CauseValidation property of Button: If false then button does not causes validation to
fire.
Example:

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 3


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" %>


<html>
<head>
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div> Your
Age
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox1"
Type="Integer"
MinimumValue="18"
MaximumValue="60"
Text="(Out of 18-60)"
ToolTip="Input value between 18-60" ErrorMessage="Out
of range(18-60)" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button2" runat="server" Text="Cancel" CausesValidation="False" />
</div>
</form>
</body>
</html>

CompareValidator control:

This validation control performs three type of validation.


1. Check data type of value.
2. Compare input value against fixed value.
3. Compare input value against another input value.
Syntax:
<asp:CompareValidator ID="CompareValidator1"
runat="server" />
Important Properties:
- ControlToValidate: ID of control to be validate.
- ControlToCompare: ID of the control to compare with.
- Type: Data type of values for comparison. (String / Integer / Double / Date /
Currency)
- Operator: Comparison operation to apply to value. (Equal /
NotEqual / GreaterThan / …)
- ValueToCompare: The fixed value to compare against.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 4


22UCSCC62 : DOTNET PROGRAMMING

- Text: text to display for the validator when the validated control is invalid.
- ErrorMessage: Message to display in a ValidationSummary when the
validated control is invalid.
- ToolTip: The tooltip displayed when the mouse is over the control.
- EnableClientScript: If it is true then validation is performed at client side by
browser otherwise performed at server side.

CauseValidation property of Button: If false then button does not causes validation to fire.
Example1: Check data type.

<%@ Page Language="C#" %>


<html>
<head><title>Untitled Page</title></head>
<body>
<form id="form1" runat="server">
<div>
Date of Birth
<asp:TextBox ID="TextBox1" runat="server"/>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="TextBox1" Operator="DataTypeCheck"
Type="Date"
Text="(Invalid (mm/dd/yyyy)" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button runat="server" Text="Cancel" CausesValidation="False" />
</div>
</form>
</body>
</html>
Example2: Check input integer value is more than 18.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 5


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" %>


<html>
<head><title>Untitled Page</title></head>
<body>
<form id="form1" runat="server">
<div>
Your age
<asp:TextBox ID="TextBox1" runat="server"/>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="TextBox1"
Operator="GreaterThan" Type="Integer"
ValueToCompare="18" Text="(Input more
than18)" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button runat="server" Text="Cancel" CausesValidation="False" />
</div>
</form>
</body>
</html>
Example3: Compare input password to confirm password.

<%@ Page Language="C#" %>


<html>
<head><title>Untitled Page</title></head>
<body>
<form id="form1" runat="server">
<div>
Your password
<asp:TextBox ID="TextBox1" runat="server" TextMode="Password" />
<br />
Confirm Password
<asp:TextBox ID="TextBox2" runat="server" TextMode="Password" />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="TextBox1"
ControlToValidate="TextBox2"
Type="String"

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 6


22UCSCC62 : DOTNET PROGRAMMING

Operator="Equal"
Text="(Password Not matched)" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button runat="server" Text="Cancel" CausesValidation="False" />
</div>
</form>
</body>
</html>

RegularExpressionValidator control:

This validation control compares input value against a regular expression. We can use a
regular expression to represent string pattern such as email address, dates etc.
Syntax:
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" />
Important Properties:
- ControlToValidate: ID of control to be validate.
- ValidationExpression:The Regular expression is assigned to this property.
(http://regexlib.com for all list)
- Text: text to display for the validator when the validated control is invalid.
- ErrorMessage: Message to display in a ValidationSummary when the
validated control is invalid.
- ToolTip: The tooltip displayed when the mouse is over the control.
- EnableClientScript: If it is true then validation is performed at client side by
browser otherwise performed at server side.

CauseValidation property of Button: If false then button does not causes validation to
fire.
Example: Check valid EmailID format

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 7


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" %>


<html>
<head><title>Untitled Page</title></head>
<body>
<form id="form1" runat="server">
<div>
Your Email ID
<asp:TextBox ID="TextBox1" runat="server"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox1" ValidationExpression=
"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Text="(Invalid EmailID
format" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button runat="server" Text="Cancel" CausesValidation="False" />
</div>
</form>
</body>
</html>

ValidationSummary control:

This control display a list of all validation errors which are given in ErrorMessage
of each validation control.
Syntax:
<asp:ValidationSummary ID=" ValidationSummary1" runat="server" />
Important Properties:
- DisplayMode: Format for error summary display. (BulletList /
SingleParaGraph / List)
- HeaderText: To display header text on the top of summary control.
- ShowMessageBox: True means display a popup alert box.
- ShowSummary: False then summary hides.

CauseValidation property of Button: If false then button does not causes validation to
fire.
Example: Show summary of validation of all validation controls.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 8


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" %>


<html>
<head>
<title>Untitled Page</title></head>
<body>
<form id="form1" runat="server">
<div>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" />
<br /> Your
Name
<asp:TextBox ID="TextBox1" runat="server"/>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ControlToValidate="TextBox1"
ErrorMessage="Input your Name"
Text="*" />
<br />
Your age
<asp:TextBox ID="TextBox2" runat="server" />
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="TextBox2" ErrorMessage="Input age 18-
60" MaximumValue="60" MinimumValue="18"
Type="Integer" Text="*" />
<br />
Your Birth Date
<asp:TextBox ID="TextBox3" runat="server" />
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToValidate="TextBox3" ErrorMessage="Invalid date
format" Operator="DataTypeCheck"
Type="Date" Text="*" />
<br />
Your Email ID
<asp:TextBox ID="TextBox4" runat="server"/>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="TextBox4"

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 9


22UCSCC62 : DOTNET PROGRAMMING

ErrorMessage="Invalid Email ID Format" ValidationExpression=


"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Text="*" />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
<asp:Button ID="Button2" runat="server" Text="Cancel"
CausesValidation="False" />
</div>
</form>
</body>
</html>

CustomValidator control:

If none of the other validation controls perform the type of validation that we need then
we can use CustomValidator control. In this control, we can associate function for a
custom validation.
Syntax:
<asp:CustomValidator ID="CustomValidator1" runat="server" />
Important Properties:
- ControlToValidate: ID of control to be validate.
- Text: text to display for the validator when the validated control is invalid.
- ErrorMessage: Message to display in a ValidationSummary when the
validated control is invalid.
- ServerValidate(Event): This event raised when the CustomValidator performs
validation.

CauseValidation property of Button: If false then button does not causes validation to
fire.

Example: Check input string length is greater than 10.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 10


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" %>


<script runat="server">
void CustomValidator1_ServerValidate(object source,
ServerValidateEventArgs args)
{
if (args.Value.Length <= 10) args.IsValid = true;
else
args.IsValid = false;
}
</script>

<html>
<head><title>Custome Validation Page</title></head>
<body>
<form id="form1" runat="server">
<div>
Input string of 10 character
<asp:TextBox ID="TextBox1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox1"
OnServerValidate="CustomValidator1_ServerValidate" Text="(String Length is
greater than 10) />
<br />
<asp:Button ID="Button1" runat="server" Text="Submit" />
</div>
</form>
</body>
</html>

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 11


22UCSCC62 : DOTNET PROGRAMMING

Basics of Regular expression

d (for digits)
w (for character)
{n} (n is exact number of allowed digits or character) [a-z](match any one
specified character)
+ (for one or more d/w)
\ (flow of d/w)

for example:

\d{1} to allow only one digits ex: 0 to 9


\d{5} to allow only 5 digits ex:00000 to 99999
\w{6} to allow only 6 character ex: lokesh, ujjain, p-1234
\d+ to allow one or more digits ex: 1, 21, 345 5444
\w+ to allow one or more digits ex: l, lo, lok5444 d{4}(-

d{5}) to allow 4 digits - 5 digits (3234-32434)

***for one character** [a]


[ad] [a-
z]
[A-Z]
[0-9]
[-+*/]

***one or more ***


digits(233) : \d+ Small
Alphabet(lokesh) : [a-z]+
Capital Alphabet(lokesh) : [A-Z]+
digits with one . dot(233.23) : \d+(.\d+)
***fix number of ***
5 digits(233) : \d{5}
5Small Alphabet(lokesh) : [a-z]{5}
(5,2)digits with one . dot(233.23) : \d{5}(.\d{2})

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 12


22UCSCC62 : DOTNET PROGRAMMING

Calendar control:

The Calendar control displays a calendar that can use as a date picker or to display a list of
upcoming events.

Syntax:
<asp:Calendar ID="Calendar1" runat="server"/ >
Properties:
- Caption: The caption associated with calender.
- DayNameFormat: To set day name as(Mon/Monday/Mo/M.
- FirstDayOfWeek:Which day of week display first. (Sun/Mon/Tue..).
- NextMonthText: To set text for next month Button.(&gt for >).
- PrevMonthText: To set text for previous month Button. (&lt for <).
- NextPrevFormat: To set format for Next and Previous month
navigation buttons.(ShortMonth / FullMonth/ CustomText).
- SelectedDate: To get or set selected date.
- SelectedDates: To get multiple dates(C#).
- ShowDayHeader: If false then dayname becomes hides.
- ShowNextPrevMonth: If false then next and previous month hides.
- ShowTitle: If false then title of calender hides.
- TitleFormat: Set Month or Month Year.
- VisibleDate: Set the month of calender.
- SelectionMode: To set selection day/week/month.

Events:
- DayRender: Raised as each day is rendered.
- SelectionChanged: Raised when a new day, week, or month is selected.
- VisibleMonthChanged: Raised when the next or previous month link is clicked.
Example: Show all dates of selected week in a bullet list control.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 13


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" %>


<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
BulletedList1.DataSource = Calendar1.SelectedDates; BulletedList1.DataBind();
}
</script>

<html>
<head><title>Get Selected Dates Page</title></head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" runat="server"
SelectionMode="DayWeekMonth"></asp:Calendar>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Submit" />
<asp:BulletedList ID="BulletedList1" runat="server"
DataTextFormatString="{0:d}"></asp:BulletedList>
</div>
</form>
</body>
</html>

AdRotator control:

The AdRotator control is used to randomly display images of different advertisements in


a page. List of advertisements can be stored in an XML file or in a database table.
Syntax:
<asp:AdRotator ID="AdRotator1" runat="server" />
Properties:
- AdvertisementFile: To specify path of XML file containing
advertisements.
- AlternateTextField: The element name (AlternateText) that specify which
alternate text to retrieve.
- ImageUrlField: The element name (ImageUrl) that specify which image URL
to retrieve.
- NavigateUrlField: The element name (NavigateUrl) that specify which
advertisement web page URL to retrieve.
Events:
- AdCreated: Raised after the AdRotator control selects an advertisement but
before the AdRotator control renders the advertisement.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 14


22UCSCC62 : DOTNET PROGRAMMING

Procedure to add advertisements on AdRotator control using XML file.

1) Add AdRotator control on web page. (AdRotator1)


2) Create AdImage folder in root folder of website.
3) Copy Ad Images into AdImage folder.(let ad1.jpg, ad2.jpg)
4) Open an XML: Add New Item🡪add XML file(adXML.xml)
5) Write following XML code to add list of ad images.

<Advertisements>
<Ad>
<ImageUrl>~/AdImage/Ad1.jpg</ImageUrl>
<AlternateText>LRsir</AlternateText>
<NavigateUrl>http://www.LRsir.net</NavigateUrl>
<Impressions>50</Impressions>
<Keyword>banner</Keyword>
<Width>400</Width>
<Height>200</Height>
</Ad>

<Ad>
<ImageUrl>~/AdImage/Ad2.jpg</ImageUrl>
<AlternateText>Advance College</AlternateText>
<NavigateUrl>www.advcolcom</NavigateUrl>
<Impressions>20</Impressions>
<Keyword>banner</Keyword>
<Width>400</Width>
<Height>200</Height>
</Ad>
</Advertisements>
6) Attach adXML.xml file to AdvertisementFile property and add
Keyword value to KeywordFilter property.
<asp:AdRotator ID="AdRotator1" runat="server" KeywordFilter="banner"
AdvertisementFile="~/AdXMLFile.xml" />

When web page is refreshed then Ad images replaced by another Ad images. Number of
occurrence of any advertisement depends upon impressions value.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 15


22UCSCC62 : DOTNET PROGRAMMING

ASP.NET - Multi Views


MultiView and View controls allow you to divide the content of a page into different
groups, displaying only one group at a time. Each View control manages one group of
content and all the View controls are held together in a MultiView control.

The MultiView control is responsible for displaying one View control at a time. The View
displayed is called the active view.

The syntax of MultiView control is:

<asp:MultView ID= "MultiView1" runat= "server">


</asp:MultiView>

The syntax of View control is:

<asp:View ID= "View1" runat= "server">


</asp:View>

However, the View control cannot exist on its own. It would render error if you try to use
it stand-alone. It is always used with a Multiview control as:

<asp:MultView ID= "MultiView1" runat= "server">


<asp:View ID= "View1" runat= "server"> </asp:View>
</asp:MultiView>

Properties of View and MultiView Controls


Both View and MultiView controls are derived from Control class and inherit all its
properties, methods, and events. The most important property of the View control is
Visible property of type Boolean, which sets the visibility of a view.

The MultiView control has the following important properties:

Properties Description

Views Collection of View controls within the MultiView.

A zero based index that denotes the active view. If no view is active, then the
ActiveViewIndex
index is -1.

The CommandName attribute of the button control associated with the navigation of the
MultiView control are associated with some related field of the MultiView control.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 16


22UCSCC62 : DOTNET PROGRAMMING

For example, if a button control with CommandName value as NextView is associated


with the navigation of the multiview, it automatically navigates to the next view when the
button is clicked.

The following table shows the default command names of the above properties:

Properties Description

NextViewCommandName NextView

PreviousViewCommandName PrevView

SwitchViewByIDCommandName SwitchViewByID

SwitchViewByIndexCommandName SwitchViewByIndex

The important methods of the multiview control are:

Methods Description

SetActiveview Sets the active view

GetActiveview Retrieves the active view

Every time a view is changed, the page is posted back to the server and a number of
events are raised. Some important events are:

Events Description

ActiveViewChanged Raised when a view is changed

Activate Raised by the active view

Deactivate Raised by the inactive view

Apart from the above mentioned properties, methods and events, multiview control
inherits the members of the control and object class.

Example
The example page has three views. Each view has two button for navigating through the
views.

The content file code is as follows:

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 17


22UCSCC62 : DOTNET PROGRAMMING

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"


Inherits="multiviewdemo._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">
<title>
Untitled Page
</title>
</head>

<body>
<form id="form1" runat="server">

<div>
<h2>MultiView and View Controls</h2>

<asp:DropDownList ID="DropDownList1" runat="server"


onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>

<hr />

<asp:MultiView ID="MultiView1" runat="server"


ActiveViewIndex="2" onactiveviewchanged="MultiView1_ActiveViewChanged" >
<asp:View ID="View1" runat="server">
<h3>This is view 1</h3>
<br />
<asp:Button CommandName="NextView" ID="btnnext1"
runat="server" Text = "Go To Next" />
<asp:Button CommandArgument="View3"
CommandName="SwitchViewByID" ID="btnlast" runat="server" Text ="Go To
Last" />
</asp:View>

<asp:View ID="View2" runat="server">


<h3>This is view 2</h3>
<asp:Button CommandName="NextView" ID="btnnext2"
runat="server" Text = "Go To Next" />
<asp:Button CommandName="PrevView" ID="btnprevious2"
runat="server" Text = "Go To Previous View" />
</asp:View>

<asp:View ID="View3" runat="server">


<h3> This is view 3</h3>
<br />
<asp:Calendar ID="Calender1"
runat="server"></asp:Calendar>

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 18


22UCSCC62 : DOTNET PROGRAMMING

<br />
<asp:Button CommandArgument="0"
CommandName="SwitchViewByIndex" ID="btnfirst" runat="server" Text = "Go
To Next" />
<asp:Button CommandName="PrevView" ID="btnprevious"
runat="server" Text = "Go To Previous View" />
</asp:View>

</asp:MultiView>
</div>

</form>
</body>
</html>

The MultiView.ActiveViewIndex determines which view will be shown. This is the only
view rendered on the page. The default value for the ActiveViewIndex is -1, when no view
is shown. Since the ActiveViewIndex is defined as 2 in the example, it shows the third
view, when executed.

N.MANIMOZHI-AP/ DEPARTMENT OF COMPUTER APPLICATION- RASC Page 19

You might also like