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

Web Development CAP426 HW3

The document discusses validation controls in ASP.NET web forms. It provides examples of using the RequiredFieldValidator, RangeValidator, RegularExpressionValidator controls to validate user input. It also discusses the Role of the LoginStatus control and provides an example of how to implement password recovery using the PasswordRecovery control in ASP.NET.

Uploaded by

Aditya Nath
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Web Development CAP426 HW3

The document discusses validation controls in ASP.NET web forms. It provides examples of using the RequiredFieldValidator, RangeValidator, RegularExpressionValidator controls to validate user input. It also discusses the Role of the LoginStatus control and provides an example of how to implement password recovery using the PasswordRecovery control in ASP.NET.

Uploaded by

Aditya Nath
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

HOMEWORK NO:3

CAP426: Web Development


DOA: 29th March,11
DOS: 08th April, 11

Part-A

1. Write down the name of validation control with explanation for following:
a. Which control is required when a value is required for an input on the web
page

Ans :

RequiredFieldValidator:- The RequiredFieldValidator control is simple validation


control which checks to see if the data is entered for the attached control. You can
have a RequiredFieldValidator control for each form element on which you wish
to enforce Mandatory Field rule.

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


    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Required!" ControlToValidate="TextBox1">
        </asp:RequiredFieldValidator>
        <asp:Button ID="Button1" runat="server" Text="Submit"
CausesValidation="true"/>
    </div>
    </form>

b. Which control is required when we want to match input values with some
constants

Ans:

RangeValidator Server Control :-The RangeValidator Server Control makes sure that
the end user value or selection provided is between a specified ranges. Below given
example should give you clear picture .
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="Value must be between 20 and 30"
ControlToValidate="RangeTextbox"
        Type="Integer" MinimumValue="20" MaximumValue="30" >
        </asp:RangeValidator>
        <asp:TextBox ID="RangeTextbox" runat="server"></asp:TextBox>
        <asp:Button ID="CheckRange" runat="CheckRange" Text="Button" />
c. Which control is required when we want to check value from the range of
values
Ans :

RangeValidator Server Control :-The RangeValidator Server Control makes sure that
the end user value or selection provided is between a specified ranges. Below given
example should give you clear picture .
<asp:RangeValidator ID="RangeValidator1" runat="server"
ErrorMessage="Value must be between 20 and 30"
ControlToValidate="RangeTextbox"
        Type="Integer" MinimumValue="20" MaximumValue="30" >
        </asp:RangeValidator>
        <asp:TextBox ID="RangeTextbox" runat="server"></asp:TextBox>
        <asp:Button ID="CheckRange" runat="CheckRange" Text="Button" />

d. Which control is required to match input with some pattern of a regular


expression
Ans :

RegularExpressionValidator Server Control:-Using RegularExpressionValidator


server control, you can check a user's input based on a pattern that you define using a
regular expression. This means that you can define a structure that a user's input will be
applied against to see if its structure matches the one that you define .
 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" 
ControlToValidate="Textbox4" runat="server"
        ErrorMessage="You must enter an email address"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">
</asp:RegularExpressionValidator>
        <asp:Button ID="Button3" runat="server" Text="CheckMail"/>

e. Which control is required to capture all the validation errors on the page

ValidationSummary Server Control:-The ValidationSummary control is reporting control,


which is used by the other validation controls on a page. You can use this validation control
to consolidate errors reporting for all the validation errors that occur on a page instead of
leaving this up to each and every individual validation control .
<asp:ValidationSummary ID="ValidationSummary1" DisplayMode="BulletList" 
HeaderText="You received following errors" runat="server" />
2. Create a web application for displaying sessions on various web pages. Also give
sessions time out after 2mins and kill the session using various functionality.
Ans :
Code of first page:-
<%@ Page Language=”C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=”server”>
void Page_Load()
{
Session[“message”] = “kapil”;
}
</script>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head id=”Head1” runat=”server”>
<title>Session Set</title>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<h1>Session item added!</h1>
</div>
</form>
</body>
</html>

Web.Config
<configuration>
<system.web>
<sessionState timeout=”2” />
</system.web>
</configuration>

Code of second page:-

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


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<script runat=”server”>
void Page_Load()
{
lblMessage.Text = Session[“message”].ToString();
Session.abandon();
}
</script>
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head id=”Head1” runat=”server”>
<title>Session Get</title>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<asp:Label
id=”lblMessage”
Runat=”server” />
</div>
</form>
</body>
</html>

3. Elaborate the role of Login Status Control with an example.

Ans:
LoginStatus:-Enables you to display either a log in or log out link, depending on a
user’s authentication status.

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


<!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 id=”Head1” runat=”server”>
<title>Show LoginStatus</title>
</head>
<body>
<form id=”form1” runat=”server”>
<div>
<asp:LoginStatus
id=”LoginStatus1”
Runat=”server”
LoginText="Sign In"
LogoutText="Sign Out"
LogoutPageUrl="~/Default.aspx"
LogoutAction="Redirect"
onloggedout="LoginStatus1_LoggedOut"/>
</div>
</form>
</body>
</html>

Part-B
4. List out the categories of controls available in ASP.NET with brief description.

Ans :
The ASP.Net framework contains over 70 controls. These controls can be
divided into 7 groups:

1) Standard Controls: The standard controls enables you to render standard


form elements such as buttons, input fields and labels.

2) Validation Controls: The validation controls enable you to validate form data
before you submit the data to the server. For example, you can use a
RequiredFieldValidator control to check whether a user entered a value for a
required input field.

3) Rich Controls: The Rich controls enable you to render things such as
calendars, file upload buttons, rotating banner advertisements and multi-step
wizards.

4) Data Controls: The data controls enable you to work with data such as
database data. For example, you can use these controls to submit new records
to a database table or display a list of database records.

5) Navigation Controls: The navigation controls enable you to display standard


navigation elements such as menus, tree views, and bread crumb trails.

6) Login Controls: The login controls enable you to display login, change
password, and registration forms.

7) HTML Controls: The HTML controls enable you to convert any HTML tag into
a server-side control.

5. How you will recover the password using password Recover Control? Give an
example.

Ans :

To enable password recovery follow following steps:-


1. Create or edit an ASP.NET Web page on your site that is accessible to
anonymous users (for example, RecoverPassword.aspx). In an authenticated
Web site, you can use the location configuration element to specify that a page
can be accessed anonymously, as shown in the following example:

location configuration element to specify that a page can be accessed


anonymously, as shown in the following example:
<configuration>
<location path="RecoverPassword.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>

<system.web>
<authentication mode="Forms" >
<forms loginUrl="UserLogin.aspx" />
</authentication>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>

2.Place a PasswordRecovery control on the page as shown in the following


example:

<asp:PasswordRecovery ID="PasswordRecovery1" Runat="server">


</asp:PasswordRecovery>

3.Optionally configure the following templates to customize the appearance of


that PasswordRecovery control: UserNameTemplate, QuestionTemplate, and
SuccessTemplate.

6. Create a web form for various objects (like session, application, Request,
Response, cookies etc.) used in one web form.
Ans:
Code of page one:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page


{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["sess"] = "session";
        Application["app"] = "application";
        HttpCookie ck = new HttpCookie("cookie");
        ck["a"] = "cookie";
        Response.Cookies.Add(ck);
        ViewState["view"] = "viewstate";
        Response.Redirect("second.aspx?name=kapil");

    }
}

code of page two

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class second : System.Web.UI.Page


{
    protected void Page_Load(object sender, EventArgs e)
    {
        string query = Request.QueryString["name"];
        HttpCookie ck = Request.Cookies["cookie"];
        Response.Write("this is querystring variable "+query+"<br>this is application object
"+Application["app"].ToString()+"<br>This is session object
"+Session["sess"].ToString()+"<br>This is viewstate object
"+ViewState["view"].ToString()+"<br>This is cookie"+ck["a"].ToString()+"");
    }
}

You might also like