34
14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary) DEGREE EXAMINATION November, 2018 Computer Science & Engineering Fifth Semester Enterprise Programming-I Time: Three Hours Maximum: 60 Marks Answer Question No.1 compulsorily. (1X12 = 12 Marks) Answer ONE question from each unit. (4X12=48 Marks) 1. Answer all questions (1X12=12 Marks) a) What is CLR? b) Define AutoPostBack. c) Differentiate Server.Transfer and Response.Redirect. d) How to add Themes to our application? e) List the elements of AdRotator’s advertisement file. f) What is the use of master page? g) Write an example SQL Delete statement. h) Write the differences between form view and details view. i) Define LINQ. j) What is the difference between DataReader and DataSet? k) Describe interoperable application. l) List the different ways to publish an ASP.NET website. UNIT I 2. a) Explain the various list controls available in ASP with an example program. 8M b) Write an ASP.NET application to read the number of rows and columns from the user to create a table dynamically. 4M (OR) 3. a) Describe the steps to create a Greeting Card in ASP.NET using web controls. 8M b) Explain in detail about tracing. 4M UNIT II 4. a) What are the validation controls supported by ASP.NET? Explain with an example 6M b) Discuss about Styles and Themes. 6M (OR) 5. a) What are the advantages and drawbacks of using of Cookies? Explain how server sets a cookie and retrieves it. 6M b) Explain in detail about Session State state management technique. 6M UNIT III 6. a) Design an ASP.NET application to demonstrate Grid view and explain its features. 6M b) Create an ASP.NET application to perform select, insert and update operations on SQL server database using connected model. 6M (OR) 7. a) Explain in detail about single valued data binding and multi valued data binding. 6M b) Demonstrate LINQ to objects with an example ASP.NET application. 6M UNIT IV 8. a) Explain about MVC and its advantages. 6M b) Design party invites MVC application. 6M (OR) 9. a) Discuss in detail about WCF service. 6M b) Design an application to demonstrate creating and consuming a WCF Web Service. 6M

14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Embed Size (px)

Citation preview

Page 1: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

14CS505 Hall Ticket Number:

III/IV B.Tech (Regular/Supplementary) DEGREE EXAMINATION

November, 2018 Computer Science & Engineering

Fifth Semester Enterprise Programming-I Time: Three Hours Maximum: 60 Marks

Answer Question No.1 compulsorily. (1X12 = 12 Marks)

Answer ONE question from each unit. (4X12=48 Marks)

1. Answer all questions (1X12=12 Marks)

a) What is CLR?

b) Define AutoPostBack.

c) Differentiate Server.Transfer and Response.Redirect.

d) How to add Themes to our application?

e) List the elements of AdRotator’s advertisement file.

f) What is the use of master page?

g) Write an example SQL Delete statement.

h) Write the differences between form view and details view.

i) Define LINQ.

j) What is the difference between DataReader and DataSet?

k) Describe interoperable application.

l) List the different ways to publish an ASP.NET website.

UNIT I

2. a) Explain the various list controls available in ASP with an example program. 8M

b) Write an ASP.NET application to read the number of rows and columns from the user to create a

table dynamically.

4M

(OR)

3. a) Describe the steps to create a Greeting Card in ASP.NET using web controls. 8M

b) Explain in detail about tracing. 4M

UNIT II

4. a) What are the validation controls supported by ASP.NET? Explain with an example 6M

b) Discuss about Styles and Themes. 6M

(OR)

5. a) What are the advantages and drawbacks of using of Cookies? Explain how server sets a cookie and

retrieves it.

6M

b) Explain in detail about Session State state management technique. 6M

UNIT III 6. a) Design an ASP.NET application to demonstrate Grid view and explain its features. 6M

b) Create an ASP.NET application to perform select, insert and update operations on SQL server

database using connected model.

6M

(OR) 7. a) Explain in detail about single valued data binding and multi valued data binding. 6M

b) Demonstrate LINQ to objects with an example ASP.NET application. 6M

UNIT IV 8. a) Explain about MVC and its advantages. 6M

b) Design party invites MVC application. 6M

(OR) 9. a) Discuss in detail about WCF service. 6M

b) Design an application to demonstrate creating and consuming a WCF Web Service. 6M

Page 2: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

1. Answer all questions (1X12=12 Marks)

a) What is CLR?

This is the engine that executes all .NET programs and provides automatic services for these

applications, such as security checking, memory management, and optimization.

b) Define AutoPostBack.

Autopostback is the mechanism, by which the page will be posted back to the server

automatically based on some events in the web controls. In some of the web controls, the property

called auto post back, which if set to true, will send the request to the server when an event

happens in the control.

c) Differentiate Server.Transfer and Response.Redirect.

Server.Transfer Response.Redirect

Response.Redirect() will send you to a new

page, update the address bar and add it to the

Browser History. On your browser you can

click back.

Server.Transfer() does not change the address

bar, we cannot hit back.One should use

Server.Transfer() when he/she doesn’t want

the user to see where he is going. Sometime

on a "loading" type page.

It redirects the request to some plain HTML

pages on our server or to some other web

server.

It transfers current page request to another

.aspx page on the same server.

It causes additional roundtrips to the server on

each request.

It preserves server resources and avoids the

unnecessary roundtrips to the server.

It doesn’t preserve Query String and Form

Variables from the original request.

It preserves Query String and Form Variables.

Note: Give full marks for any two differences.

d) How to add Themes to our application?

To add a theme to your project, select Website➤ Add New Item, and choose Skin File. Visual

Studio will warn you that skin files need to be placed in a subfolder of the App_Thmes folder and

ask you whether that’s what you intended. If you choose Yes, Visual Studio will create a folder

with the same name as your theme file.

e) List the elements of AdRotator’s advertisement file.

ImageUrl

NavigateUrl

AlternateText

Impressions

Keyword

f) What is the use of master page?

Master pages enable consistent and standardized layout of the website.

You can make layout changes of the site in the master page instead of making changes in

the pages.

It provides an object model which allows you to customize the master page from

individual content pages.

It allows you to centralize the common functionality of your pages so that you can make

updates in just one place.

Note: Give full marks for any two uses.

Page 3: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

g) Write an example SQL Delete statement.

Syntax:

DELETE FROM table_name WHERE condition;

Example

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

h) Write the differences between form view and details view.

The FormView control provides more control over the layout.

The FormView control uses only the templates with databinding expressions to display

data. The DetailsView control uses <BoundField> elements or <TemplateField> elements.

i) Define LINQ.

LINQ (Language Integrated Query) is uniform query syntax in C# and VB.NET used to save and

retrieve data from different sources.

(OR)

LINQ defines keywords that you can use to select, filter, sort, group, and transform data. The

minor miracle of LINQ is that different LINQ providers allow these keywords to work with

different types of data.

j) What is the difference between DataReader and DataSet?

DataReader DataSet

Used in Direct/Connected Data Access Model Used in DisConnected Data Access Model

Holds the connection open until you are

finished

Keeps connection alive until retrieves data

from data source.

Can iterate in forward only direction. Can iterate in both direction.

Note: Give full marks for any two differences.

k) Describe interoperable application.

An application that can communicate with any another application built on any platform is

called interoperable application.

l) List the different ways to publish an ASP.NET website.

Manual Deployment

Using Visual Studio

UNIT I

2. a) Explain the various list controls available in ASP with an example program.

The list controls include the ListBox, DropDownList, CheckBoxList,

RadioButtonList, and BulletedList. They all work in essentially the same way but are

rendered differently in the browser. The ListBox, for example, is a rectangular list that

displays several entries, while the DropDownList shows only the selected item. The

CheckBoxList and RadioButtonList are similar to the ListBox, but every item is rendered as

a check box or option button, respectively. Finally, the BulletedList is the odd one out—it’s

the only list control that isn’t selectable. Instead, it renders itself as a sequence of numbered

or bulleted items.

All the selectable list controls provide a SelectedIndex property that indicates the

selected row as a zero based index (just like the HtmlSelect control you used in the previous

chapter). For example, if the first item in the list is selected, the SelectedIndex will be 0.

Selectable list controls also provide an additional SelectedItem property, which allows your

code to retrieve the ListItem object that represents the selected item. The ListItem object

provides three important properties: Text (the displayed content), Value (the hidden value

from the HTML markup), and Selected (true or false depending on whether the item is

selected).

8M

Page 4: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Example:

Default.aspx

<%@ Page Trace="true" Language="C#" AutoEventWireup="true"

CodeFile="Default.aspx.cs" Inherits="_Default" ViewStateEncryptionMode="Always" %>

<!DOCTYPE html>

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

<head runat="server">

<title></title>

</head>

<body>

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

<div>

Choose your Favourite Pogramming Language:<br />

<asp:DropDownList AutoPostBack="true" ID="dllist" runat="server"

OnSelectedIndexChanged="dllist_SelectedIndexChanged"></asp:DropDownList><br />

<asp:Label ID="lbldllist" runat="server"></asp:Label><br />

<hr />

Choose your Favourite Pogramming Language:<br />

<asp:RadioButtonList ID="optlist" runat="server"></asp:RadioButtonList><br />

<asp:Label ID="lbloptlist" runat="server"></asp:Label><br />

<hr />

Choose your Favourite Pogramming Language:<br />

<asp:ListBox ID="lstlist" SelectionMode="Multiple"

runat="server"></asp:ListBox><br />

<asp:Label ID="lbllstlist" runat="server"></asp:Label><br />

<hr />

Choose your Favourite Pogramming Language:<br />

<asp:CheckBoxList ID="chklist" runat="server"></asp:CheckBoxList><br />

<asp:Label ID="lblchklist" runat="server"></asp:Label><br />

<hr />

<asp:Button ID="select" Text="Select" OnClick="select_Click" runat="server" />

<hr />

<asp:BulletedList ID="blist" runat="server" BulletStyle="Numbered"

FirstBulletNumber="3" DisplayMode="LinkButton" OnClick="blist_Click">

<asp:ListItem>C</asp:ListItem>

<asp:ListItem>C++</asp:ListItem>

<asp:ListItem>C#</asp:ListItem>

<asp:ListItem>Java</asp:ListItem>

</asp:BulletedList>

<asp:Label ID="lblblist" runat="server"></asp:Label>

</div>

</form>

</body>

</html>

Note: Designer is also valid

Page 5: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Default.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

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

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack) {

lstlist.Items.Add(new ListItem("C"));

lstlist.Items.Add(new ListItem("C++"));

lstlist.Items.Add(new ListItem("C#"));

lstlist.Items.Add(new ListItem("Java"));

optlist.Items.Add(new ListItem("C"));

optlist.Items.Add(new ListItem("C++"));

optlist.Items.Add(new ListItem("C#"));

optlist.Items.Add(new ListItem("Java"));

dllist.Items.Add(new ListItem("C"));

dllist.Items.Add(new ListItem("C++"));

dllist.Items.Add(new ListItem("C#"));

dllist.Items.Add(new ListItem("Java"));

chklist.Items.Add(new ListItem("C"));

chklist.Items.Add(new ListItem("C++"));

chklist.Items.Add(new ListItem("C#"));

chklist.Items.Add(new ListItem("Java"));

}

}

protected void select_Click(object sender, EventArgs e)

{

lbloptlist.Text = "Your Selected Language: " + optlist.SelectedItem.Text;

lbllstlist.Text = "Your Selected Language: " + lstlist.SelectedItem.Text;

lblchklist.Text = "Your Selected Language: ";

foreach (ListItem i in chklist.Items) {

if (i.Selected)

lblchklist.Text += "<br />"+i.Text;

}

}

protected void blist_Click(object sender, BulletedListEventArgs e)

Page 6: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

{

lblblist.Text = blist.Items[e.Index].Text;

}

protected void dllist_SelectedIndexChanged(object sender, EventArgs e)

{

lbldllist.Text = "Your Selected Language: " + dllist.SelectedItem.Text;

}

}

Note: Give full marks for any valid example

b) Write an ASP.NET application to read the number of rows and columns from the user

to create a table dynamically.

Default2.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"

Inherits="Default2" %>

<!DOCTYPE html>

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

<head runat="server">

<title></title>

</head>

<body>

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

<div>

<asp:Label Text="Rows:" runat="server"></asp:Label>

<asp:TextBox ID="txtr" runat="server"></asp:TextBox>

<asp:Label Text="Cols:" runat="server"></asp:Label>

<asp:TextBox ID="txtc" runat="server"></asp:TextBox>

<br />

<asp:CheckBox ID="chkb" Text="Put border around the cells" runat="server" />

<br />

<asp:Button ID="cmdc" runat="server" text="Create" OnClick="cmdc_Click"/>

<br /><hr />

<asp:Table runat="server" ID="tbl1"></asp:Table>

</div>

</form>

</body>

</html>

Note: Designer is also valid

Default2.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

4M

Page 7: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

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

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void cmdc_Click(object sender, EventArgs e)

{

int rows = Int32.Parse(txtr.Text);

int cols = Int32.Parse(txtc.Text);

for (int r = 0; r < rows; r++) {

TableRow newrow = new TableRow();

for (int c = 0; c < cols; c++) {

TableCell newcell = new TableCell();

newcell.Text = "Example cell (" + r + "," + c + ")";

if (chkb.Checked) {

tbl1.BorderStyle = BorderStyle.Double;

newcell.BorderStyle = BorderStyle.Inset;

}

newrow.Controls.Add(newcell);

}

tbl1.Controls.Add(newrow);

}

}

}

Note: Give full marks for any valid example

(OR)

3. a) Describe the steps to create a Greeting Card in ASP.NET using web controls.

Create an empty ASP.NET Website in Visual Studio

Right click on website folder -> Add -> Web Form choose the name as

GreetingCardMaker.aspx

Add Different Web Controls like Text Boxes, Radio Buttons, Dropdown Lists,

Check Boxes, … as shown in the following .aspx file.

GreetingCardMaker.aspx

<%@ Page language="c#" Inherits="GreetingCardMaker.GreetingCardMaker"

CodeFile="GreetingCardMaker.aspx.cs" %>

<!DOCTYPE html>

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

<head>

<title>Greeting Card Maker</title>

</head>

<body>

<form runat="server">

<div>

8M

Page 8: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

<div style="BORDER-RIGHT: thin ridge; PADDING-RIGHT: 20px;

BORDER-TOP: thin ridge; PADDING-LEFT: 20px;

FONT-SIZE: x-small; PADDING-BOTTOM: 20px; BORDER-

LEFT: thin ridge; WIDTH: 293px; PADDING-TOP: 20px;

BORDER-BOTTOM: thin ridge; FONT-FAMILY: Verdana;

HEIGHT: 486px; BACKGROUND-COLOR: lightyellow">Choose

a background color:<br />

<asp:dropdownlist ID="lstBackColor" runat="server"

Height="22px" Width="194px"></asp:dropdownlist>

<br /><br />

Choose a font:<br />

<asp:dropdownlist ID="lstFontName" runat="server"

Height="22px" Width="194px"></asp:dropdownlist>

<br /><br />

Specify a numeric font size:<br />

<asp:textbox ID="txtFontSize"

runat="server"></asp:textbox>

<br /><br />

Choose a border style:<br />

<asp:radiobuttonlist ID="lstBorder" runat="server"

Height="59px" Width="177px" Font-Size="X-Small"></asp:radiobuttonlist>

<br /><br />

<asp:checkbox ID="chkPicture" runat="server" Text="Add

the Default Picture"></asp:checkbox>

<br /><br />

Enter the greeting text below:<br />

<asp:textbox ID="txtGreeting" runat="server" Height="85px"

Width="240px" TextMode="MultiLine"></asp:textbox>

<br /><br />

<asp:button ID="cmdUpdate" runat="server" Height="24px"

Width="71px" Text="Update" onclick="cmdUpdate_Click"></asp:button>

</div>

<asp:panel ID="pnlCard" style="LEFT: 350px; POSITION: absolute;

TOP: 16px" runat="server"

Height="507px" Width="339px" HorizontalAlign="Center"><br

/>&nbsp;

<asp:Label ID="lblGreeting" runat="server" Height="150px"

Width="256px"></asp:Label>

<br /><br /><br />

<asp:Image ID="imgDefault" runat="server" Height="160px"

Width="212px" Visible="False"></asp:Image>

</asp:panel>

</div>

</form>

</body>

</html>

Note: Designer is also valid

Page 9: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

GreetingCardMaker.aspx.cs

using System;

using System.Collections;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Web;

using System.Web.SessionState;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace GreetingCardMaker

{

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

{

protected void Page_Load(object sender, System.EventArgs e)

{

if (this.IsPostBack == false)

{

// Set color options.

lstBackColor.Items.Add("White");

lstBackColor.Items.Add("Red");

lstBackColor.Items.Add("Green");

lstBackColor.Items.Add("Blue");

lstBackColor.Items.Add("Yellow");

// Set font options.

lstFontName.Items.Add("Times New Roman");

lstFontName.Items.Add("Arial");

lstFontName.Items.Add("Verdana");

lstFontName.Items.Add("Tahoma");

// Set border style options by adding a series of

// ListItem objects.

ListItem item = new ListItem();

// The item text indicates the name of the option.

item.Text = BorderStyle.None.ToString();

// The item value records the corresponding integer

// from the enumeration. To obtain this value, you

// must cast the enumeration value to an integer,

// and then convert the number to a string so it

// can be placed in the HTML page.

item.Value = ((int)BorderStyle.None).ToString();

Page 10: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

// Add the item.

lstBorder.Items.Add(item);

// Now repeat the process for two other border styles.

item = new ListItem();

item.Text = BorderStyle.Double.ToString();

item.Value = ((int)BorderStyle.Double).ToString();

lstBorder.Items.Add(item);

item = new ListItem();

item.Text = BorderStyle.Solid.ToString();

item.Value = ((int)BorderStyle.Solid).ToString();

lstBorder.Items.Add(item);

// Select the first border option.

lstBorder.SelectedIndex = 0;

// Set the picture.

imgDefault.ImageUrl = "defaultpic.png";

}

}

protected void cmdUpdate_Click(object sender, System.EventArgs e)

{

// Update the color.

pnlCard.BackColor =

Color.FromName(lstBackColor.SelectedItem.Text);

// Update the font.

lblGreeting.Font.Name = lstFontName.SelectedItem.Text;

try

{

if (Int32.Parse(txtFontSize.Text) > 0)

{

lblGreeting.Font.Size =

FontUnit.Point(Int32.Parse(txtFontSize.Text));

}

}

catch

{

// Use error handling to ignore invalid value.

}

// Update the border style.

pnlCard.BorderStyle =

Page 11: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

(BorderStyle)Int32.Parse(lstBorder.SelectedItem.Value);

// Update the picture.

if (chkPicture.Checked == true)

{

imgDefault.Visible = true;

}

else

{

imgDefault.Visible = false;

}

// Set the text.

lblGreeting.Text = txtGreeting.Text;

}

}

}

Note: Give full marks for any valid example

b) Explain in detail about tracing.

Tracing

ASP. NET provides a feature called tracing that gives you a far more convenient and

flexible way to report diagnostic information. To use tracing, you need to explicitly enable

it. There are several ways to switch on tracing. One of the easiest ways is by adding an

attribute to the Page directive in the .aspx file:

<%@ Page Trace=”true” … %>

Enabling tracing by using the built-in Trace object:

protected void Page_Load(Object sender, EventArgs e) {

Trace.IsEnabled = true;

}

Performing Application-Level Tracing: To enable application-level tracing, you need to

modify settings in the web.config file, as shown here:

<configuration>

<system.web>

<trace enabled="true" requestLimit="10" pageOutput="false" local

only="true" most recent="true"/>

</system.web>

</configuration>

4M

UNIT II

4. a) What are the validation controls supported by ASP.NET? Explain with an example

RequiredFieldValidator: Validation succeeds as long as the input control doesn’t contain

an empty string.

RangeValidator:Validation succeeds if the input control contains a value within a specific

numeric, alphabetic, or date range.

CompareValidator: Validation succeeds if the input control contains a value that matches

the value in another input control, or a fixed value that you specify.

RegularExpressionValidator: Validation succeeds if the value in an input control matches

a specified regular expression.

6M

Page 12: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

CustomValidator: Validation is performed by a user-defined function.

Example:

RegistartionForm.aspx

<%@ Page Language="C#" AutoEventWireup="true"

CodeFile="RegistrationForm.aspx.cs" Inherits="RegistrationForm" %>

<!DOCTYPE html>

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

<head runat="server">

<title></title>

</head>

<body>

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

<div>

<asp:ValidationSummary runat="server" />

User Name: <asp:TextBox ID="txtun" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator Display="None" Text="*" ID="unv" runat="server"

ForeColor="Red" ControlToValidate="txtun" ErrorMessage="Please Enter User

Name"></asp:RequiredFieldValidator>

<br />

Age: <asp:TextBox ID="txtage" runat="server"></asp:TextBox>

<asp:RangeValidator ID="agev" Display="None" runat="server" ForeColor="Red"

ControlToValidate="txtage" MinimumValue="18" MaximumValue="110" Type="Integer"

ErrorMessage="Please enter the age in the range 18 - 110"></asp:RangeValidator>

<br />

Password: <asp:TextBox ID="txtpwd" runat="server"

TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator Display="None" Text="*" ID="pwdv" ForeColor="Red"

runat="server" ControlToValidate="txtpwd" ErrorMessage="Please Enter

Password"></asp:RequiredFieldValidator>

<br />

Confirm Password: <asp:TextBox ID="txtcpwd" runat="server"

TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator Display="None" Text="*" ID="cpwdv"

ForeColor="Red" runat="server" ControlToValidate="txtcpwd" ErrorMessage="Please

Enter Confirm Password"></asp:RequiredFieldValidator>

<asp:CompareValidator Display="None" ID="cpwdcv" ForeColor="Red"

ControlToValidate="txtcpwd" ControlToCompare="txtpwd" Operator="Equal"

Type="String" runat="server" ErrorMessage="Passwords are not

matched"></asp:CompareValidator><br />

Email: <asp:TextBox ID="txtemail" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator Display="None" Text="*" ID="emailv"

ForeColor="Red" runat="server" ControlToValidate="txtemail" ErrorMessage="Please

Enter Email ID"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator Display="None" ID="emailrev" ForeColor="Red"

Page 13: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

ControlToValidate="txtemail" ValidationExpression="[a-z0-9\._]{5,32}@[a-

z]{3,}\.(com|co\.in)" runat="server" ErrorMessage="Invalid email

Fromat"></asp:RegularExpressionValidator><br />

Please Enter Odd Number: <asp:TextBox ID="txton" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator Display="None" Text="*" ID="onv" ForeColor="Red"

runat="server" ControlToValidate="txton" ErrorMessage="Please Enter Odd

Number"></asp:RequiredFieldValidator>

<asp:CustomValidator Display="None" ID="oncv" runat="server" ForeColor="Red"

ErrorMessage="Enter Odd Numbers only" OnServerValidate="oncv_ServerValidate"

ControlToValidate="txton"></asp:CustomValidator>

<asp:Button ID="cmdreg" runat="server" Text="Register" OnClick="cmdreg_Click"

/><br />

<asp:Label ID="lblstatus" EnableViewState="false" runat="server"></asp:Label>

</div>

</form>

</body>

</html>

Note: Designer is also valid (Validator control tag syntax is mandatory)

RegistrationForm.aspx.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

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

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void cmdreg_Click(object sender, EventArgs e)

{

if(Page.IsValid)

lblstatus.Text = "Registered Successfully";

}

protected void oncv_ServerValidate(object source, ServerValidateEventArgs args)

{

int val = Int32.Parse(args.Value);

if (val % 2 == 0)

args.IsValid = false;

else

args.IsValid = true;

}

}

Page 14: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Note: Give full marks for any valid example program

b) Discuss about Styles and Themes.

Styles

Styles allow you to add borders, set font details, change colors, add margin space and

padding, and so on.Web pages can use styles in three different ways:

Inline style: An inline style is a style that’s placed directly inside an HTML tag.

This can get messy, but it’s a reasonable approach for one-time formatting.

Internal style sheet: An internal style sheet is a collection of styles that are placed

in the <head> section of your web page markup. You can then use the styles from

this style sheet to format the web controls on that page. By using an internal style

sheet, a clear separation between formatting and content.

External style sheet: An external style sheet is similar to an internal style sheet,

except it’s placed in a completely separate file. This is the most powerful approach

because it gives a way to apply the same style rules to many pages.

Themes

All themes are application specific. To use a theme in a web application, you need to create

a folder that defines it. This folder needs to be placed in the App_Themes folder, which

must be placed inside the top-level directory for your web application. In other words, a

web application named SuperCommerce might have a theme named FunkyTheme in the

folder SuperCommerce\App_Themes\FunkyTheme. An application can contain definitions

for multiple themes as long as each theme is in a separate folder. Only one theme can be

active on a given page at a time. To actually make your theme accomplish anything, you

need to create at least one skin file in the theme folder. A skin file is a text file with the .skin

extension. ASP.NET never serves skin files directly; instead, they’re used behind the scenes

to define a theme. A skin file is essentially a list of control tags—with a twist. The control

tags in a skin file don’t need to completely define the control; they need only set the

properties that you want to standardize. For example, if you’re trying to apply a consistent

color scheme, you might be interested in setting only properties such as ForeColor and

BackColor.

6M

(OR)

5. a) What are the advantages and drawbacks of using of Cookies? Explain how server sets

a cookie and retrieves it.

Advantages:

1. One of the most powerful aspects of cookies is their persistence. When a cookie is

set on the client's browser, it can persist for days, months or even years. This makes

it easy to save user preferences and visit information and to keep this information

available every time the user returns to your site. Moreover, as cookies are stored on

the client's hard disk so if the server crashes they are still available.

2. Cookies work transparently without the user being aware that information needs to

be stored.

3. They lighten the load on the server's memory.

Disadvantages:

1. Sometimes clients disable cookies on their browsers in response to security or

privacy worries which will cause problem for web applications that require them.

2. Individual cookie can contain a very limited amount of information (not more than 4

kb).

3. Cookies are limited to simple string information. They cannot store complex

6M

Page 15: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

information.

4. Cookies are easily accessible and readable if the user finds and reopens.

5. Most browsers restrict the number of cookies that can be set by a single domain to

not more than20 cookies (except Internet Explorer). If you attempt to set more than

20 cookies, the oldest cookies are automatically deleted.

Example:

CookieExample.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CookieExample.aspx.cs"

Inherits="CookieExample" %>

<!DOCTYPE html>

<html>

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

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

<div>

<div style="border-right: 2px solid; padding-right: 30px; border-top: 2px solid; padding-

left: 30px; font-weight: bold; font-size: 140%; padding-bottom: 30px; border-left: 2px solid;

padding-top: 30px; border-bottom: 2px solid; font-family: Verdana; background-color:

#FFFFD9">

<asp:Label ID="lblWelcome" runat="server" EnableViewState="False" ></asp:Label>

</div>

<br />

Name:

<asp:TextBox ID="txtName" runat="server" Width="178px"></asp:TextBox>

<asp:Button ID="cmdStore" runat="server" OnClick="cmdStore_Click" Text="Create

Cookie" />

</div>

</form>

</body>

</html>

Note: Designer is also valid

CookieExample.aspx.cs

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

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

{

Page 16: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

protected void Page_Load(object sender, EventArgs e)

{

HttpCookie cookie = Request.Cookies["Preferences"];

if (cookie == null)

{

lblWelcome.Text = "<b>Unknown Customer</b>";

}

else

{

lblWelcome.Text = "<b>Cookie Found.</b><br><br>";

lblWelcome.Text += "Welcome, " + cookie["Name"];

}

}

protected void cmdStore_Click(object sender, EventArgs e)

{

// Check for a cookie, and only create a new one if

// one doesn't already exist.

HttpCookie cookie = Request.Cookies["Preferences"];

if (cookie == null)

{

cookie = new HttpCookie("Preferences");

}

cookie["Name"] = txtName.Text;

cookie.Expires = DateTime.Now.AddYears(1);

Response.Cookies.Add(cookie);

lblWelcome.Text = "<b>Cookie Created.</b><br><br>";

lblWelcome.Text += "New Customer: " + cookie["Name"];

}

}

Note: Give full marks for any valid example

b) Explain in detail about Session State state management technique.

Session-state is one of ASP.NET’s premiere features. It allows you to store any type

of data in memory on the server. The information is protected, because it is never

transmitted to the client, and it’s uniquely bound to a specific session.

ASP.NET tracks each session by using a unique 120-bit identifiers. ASP.NET uses a

proprietary algorithm to generate this value, thereby guaranteeing (statistically speaking)

that the number is unique and it’s random enough that a malicious user can’t reverse-

engineer or “guess” what session ID a given client will be using. This ID is the only piece of

session-related information that is transmitted between the web server and the client.

When the client presents the session ID, ASP.NET looks up the corresponding

session, retrieves the objects you stored previously, and places them into a special collection

so they can be accessed in your code. This process takes place automatically.

6M

Page 17: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Note: HTML Code is also valid

DEFAULT.ASPX.CS

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

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

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

Session[" Name"] = TextBox1.Text;

Session["Emai"]=TextBox2.Text;l

Response.Redirect("default2.aspx");

}

}

DEFAULT2.ASPX.CS

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

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

{

protected void Page_Load(object sender, EventArgs e)

{

Label1.Text = Session[" Name"].ToString();

Label2.Text=Session["Email"].ToString();

}

}

Note: Give full marks for any valid example

Page 18: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

UNIT III

6. a) Design an ASP.NET application to demonstrate Grid view and explain its features.

GridView.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView.aspx.cs"

Inherits="GridView" %>

<!DOCTYPE html>

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

<head runat="server">

<title></title>

</head>

<body>

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

<div>

<asp:GridView EnablePersistedSelection="true" AllowPaging="true" PageSize="10"

AllowSorting="True" ID="CGV" runat="server" AutoGenerateColumns="False"

DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" BackColor="#DEBA84"

BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3"

CellSpacing="2">

<Columns>

<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"

ReadOnly="True" SortExpression="CustomerID" />

<asp:BoundField DataField="ContactName" HeaderText="ContactName"

SortExpression="ContactName" />

<asp:BoundField DataField="Address" HeaderText="Address"

SortExpression="Address" />

<asp:BoundField DataField="Phone" HeaderText="Phone"

SortExpression="Phone" />

<asp:CommandField ButtonType="Button" ShowSelectButton="true" />

<asp:CommandField ButtonType="Button" ShowEditButton="true" />

6M

Page 19: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

</Columns>

<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />

<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />

<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White"

/>

<SortedAscendingCellStyle BackColor="#FFF1D4" />

<SortedAscendingHeaderStyle BackColor="#B95C30" />

<SortedDescendingCellStyle BackColor="#F1E5CE" />

<SortedDescendingHeaderStyle BackColor="#93451F" />

</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$

ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM

[Customers]" UpdateCommand="update Customers set ContactName=@ContactName,

Address=@Address, Phone=@Phone where

CustomerID=@CustomerID"></asp:SqlDataSource>

<asp:GridView ID="OGV" runat="server" AutoGenerateColumns="False"

DataKeyNames="OrderID" DataSourceID="OrdersDS">

<Columns>

<asp:BoundField DataField="OrderID" HeaderText="OrderID"

InsertVisible="False" ReadOnly="True" SortExpression="OrderID" />

<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"

SortExpression="CustomerID" />

<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID"

SortExpression="EmployeeID" />

<asp:BoundField DataField="OrderDate" HeaderText="OrderDate"

SortExpression="OrderDate" />

<asp:BoundField DataField="RequiredDate" HeaderText="RequiredDate"

SortExpression="RequiredDate" />

<asp:BoundField DataField="ShippedDate" HeaderText="ShippedDate"

SortExpression="ShippedDate" />

<asp:BoundField DataField="ShipVia" HeaderText="ShipVia"

SortExpression="ShipVia" />

<asp:BoundField DataField="Freight" HeaderText="Freight"

SortExpression="Freight" />

<asp:BoundField DataField="ShipName" HeaderText="ShipName"

SortExpression="ShipName" />

<asp:BoundField DataField="ShipAddress" HeaderText="ShipAddress"

SortExpression="ShipAddress" />

<asp:BoundField DataField="ShipCity" HeaderText="ShipCity"

SortExpression="ShipCity" />

<asp:BoundField DataField="ShipRegion" HeaderText="ShipRegion"

SortExpression="ShipRegion" />

<asp:BoundField DataField="ShipPostalCode" HeaderText="ShipPostalCode"

SortExpression="ShipPostalCode" />

<asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry"

Page 20: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

SortExpression="ShipCountry" />

</Columns>

</asp:GridView>

<asp:SqlDataSource ID="OrdersDS" runat="server" ConnectionString="<%$

ConnectionStrings:NorthwindConnectionString %>" SelectCommand="SELECT * FROM

[Orders] WHERE ([CustomerID] = @CustomerID)">

<SelectParameters>

<asp:ControlParameter ControlID="CGV" Name="CustomerID"

PropertyName="SelectedDataKey.Value" Type="String" />

</SelectParameters>

</asp:SqlDataSource>

</div>

</form>

</body>

</html>

Note: Designer alone is also not sufficient.

Web.config:

<?xml version="1.0"?>

<!--

For more information on how to configure your ASP.NET application, please visit

http://go.microsoft.com/fwlink/?LinkId=169433

-->

<configuration>

<connectionStrings>

<add name="NorthwindConnectionString" connectionString="Data

Source=.\sqlexpress;Initial Catalog=Northwind;Persist Security Info=True;User

ID=sa;Password=sqlserver"

providerName="System.Data.SqlClient" />

</connectionStrings>

<system.web>

<compilation debug="true" targetFramework="4.5.1" />

<httpRuntime targetFramework="4.5.1" />

</system.web>

</configuration>

Note: Give full marks for any valid example

b) Create an ASP.NET application to perform select, insert and update operations on

SQL server database using connected model.

AuthorManager.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AuthorManager.aspx.cs"

Inherits="AuthorManager" %>

<!DOCTYPE html>

6M

Page 21: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

<html>

<head runat="server">

<title>Untitled Page</title>

<link href="StyleSheet.css" rel="stylesheet" type="text/css" />

</head>

<body>

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

<div>

<div style="background-color: #FFE0C0; height: 100px; width: 601px; padding:

10px">

<br />

<asp:Label id="Label1" runat="server" Width="99px"

Height="19px">Select Author:</asp:Label>

<asp:DropDownList id="lstAuthor" runat="server" Width="187px"

Height="21px" AutoPostBack="True"

onselectedindexchanged="lstAuthor_SelectedIndexChanged"></asp:DropDownList>&nbsp

;

<asp:Button id="cmdUpdate" runat="server" Text="Update"

onclick="cmdUpdate_Click"></asp:Button>

<asp:Button id="cmdDelete" runat="server" Text="Delete"

onclick="cmdDelete_Click"></asp:Button>

<br />

<br />

<asp:Label id="Label11" runat="server" Width="99px"

Height="19px">Or:</asp:Label>

<asp:Button id="cmdNew" runat="server" Width="91px"

Height="24px" Text="Create New" onclick="cmdNew_Click"></asp:Button>&nbsp;

<asp:Button id="cmdInsert" runat="server" Width="85px"

Height="24px" Text="Insert New" onclick="cmdInsert_Click"></asp:Button>

</div>

<br />

<div style="background-color: #E0E0E0; height: 392px; width: 601px;

padding: 10px">

<asp:Label id="Label10" runat="server" Width="100px">Unique

ID:</asp:Label>

<asp:TextBox id="txtID" runat="server"

Width="184px"></asp:TextBox>&nbsp;

(required:&nbsp;###-##-#### form)<br />

<asp:Label id="Label2" runat="server" Width="100px">First

Name:</asp:Label>

<asp:TextBox id="txtFirstName" runat="server"

Width="184px"></asp:TextBox><br />

<asp:Label id="Label3" runat="server" Width="100px">Last

Name:</asp:Label>

Page 22: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

<asp:TextBox id="txtLastName" runat="server"

Width="183px"></asp:TextBox><br />

<asp:Label id="Label4" runat="server"

Width="100px">Phone:</asp:Label>

<asp:TextBox id="txtPhone" runat="server"

Width="183px"></asp:TextBox><br />

<asp:Label id="Label5" runat="server"

Width="100px">Address:</asp:Label>

<asp:TextBox id="txtAddress" runat="server"

Width="183px"></asp:TextBox><br />

<asp:Label id="Label6" runat="server"

Width="100px">City:</asp:Label>

<asp:TextBox id="txtCity" runat="server"

Width="184px"></asp:TextBox><br />

<asp:Label id="Label7" runat="server"

Width="100px">State:</asp:Label>

<asp:TextBox id="txtState" runat="server"

Width="184px"></asp:TextBox><br />

<asp:Label id="Label9" runat="server" Width="100px">Zip

Code:</asp:Label>

<asp:TextBox id="txtZip" runat="server"

Width="184px"></asp:TextBox>&nbsp;

(required: any five&nbsp;digits)<br />

<br />

<asp:Label id="Label8" runat="server" Width="93px"

Height="19px">Contract:</asp:Label>&nbsp;

<asp:CheckBox id="chkContract"

runat="server"></asp:CheckBox><br />

<br />

<asp:Label id="lblResults" runat="server" Width="575px"

Height="121px" Font-Bold="True"></asp:Label>

</div>

</div>

</form>

</body>

</html>

Note: Designer is also valid

AuthorManager.aspx.cs

using System;

using System.Data;

Page 23: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Web.Configuration;

using System.Data.SqlClient;

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

{

private string connectionString =

WebConfigurationManager.ConnectionStrings["Pubs"].ConnectionString;

protected void Page_Load(object sender, EventArgs e)

{

if (!this.IsPostBack)

{

FillAuthorList();

}

}

private void FillAuthorList()

{

lstAuthor.Items.Clear();

// Define the Select statement.

// Three pieces of information are needed: the unique id,

// and the first and last name.

string selectSQL = "SELECT au_lname, au_fname, au_id FROM Authors";

// Define the ADO.NET objects.

SqlConnection con = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand(selectSQL, con);

SqlDataReader reader;

// Try to open database and read information.

try

{

con.Open();

reader = cmd.ExecuteReader();

// For each item, add the author name to the displayed

// list box text, and store the unique ID in the Value property.

Page 24: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

while (reader.Read())

{

ListItem newItem = new ListItem();

newItem.Text = reader["au_lname"] + ", " + reader["au_fname"];

newItem.Value = reader["au_id"].ToString();

lstAuthor.Items.Add(newItem);

}

reader.Close();

}

catch (Exception err)

{

lblResults.Text = "Error reading list of names.";

lblResults.Text += err.Message;

}

finally

{

con.Close();

}

}

protected void lstAuthor_SelectedIndexChanged(object sender, EventArgs e)

{

// Define ADO.NET objects.

string selectSQL;

selectSQL = "SELECT * FROM Authors ";

selectSQL += "WHERE au_id='" + lstAuthor.SelectedItem.Value + "'";

SqlConnection con = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand(selectSQL, con);

SqlDataReader reader;

// Try to open database and read information.

try

{

con.Open();

reader = cmd.ExecuteReader();

reader.Read();

// Fill the controls.

txtID.Text = reader["au_id"].ToString();

txtFirstName.Text = reader["au_fname"].ToString();

txtLastName.Text = reader["au_lname"].ToString();

txtPhone.Text = reader["phone"].ToString();

txtAddress.Text = reader["address"].ToString();

txtCity.Text = reader["city"].ToString();

txtState.Text = reader["state"].ToString();

txtZip.Text = reader["zip"].ToString();

chkContract.Checked = (bool)reader["contract"];

Page 25: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

reader.Close();

lblResults.Text = "";

}

catch (Exception err)

{

lblResults.Text = "Error getting author. ";

lblResults.Text += err.Message;

}

finally

{

con.Close();

}

}

protected void cmdInsert_Click(object sender, EventArgs e)

{

// Perform user-defined checks.

if (txtID.Text == "" || txtFirstName.Text == "" || txtLastName.Text == "")

{

lblResults.Text = "Records require an ID, first name, and last name.";

return;

}

// Define ADO.NET objects.

string insertSQL;

insertSQL = "INSERT INTO Authors (";

insertSQL += "au_id, au_fname, au_lname, ";

insertSQL += "phone, address, city, state, zip, contract) ";

insertSQL += "VALUES (";

insertSQL += "@au_id, @au_fname, @au_lname, ";

insertSQL += "@phone, @address, @city, @state, @zip, @contract)";

SqlConnection con = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand(insertSQL, con);

// Add the parameters.

cmd.Parameters.AddWithValue("@au_id", txtID.Text);

cmd.Parameters.AddWithValue("@au_fname", txtFirstName.Text);

cmd.Parameters.AddWithValue("@au_Lname", txtLastName.Text);

cmd.Parameters.AddWithValue("@phone", txtPhone.Text);

cmd.Parameters.AddWithValue("@address", txtAddress.Text);

cmd.Parameters.AddWithValue("@city", txtCity.Text);

cmd.Parameters.AddWithValue("@state", txtState.Text);

cmd.Parameters.AddWithValue("@zip", txtZip.Text);

cmd.Parameters.AddWithValue("@contract", chkContract.Checked);

// Try to open the database and execute the update.

Page 26: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

int added = 0;

try

{

con.Open();

added = cmd.ExecuteNonQuery();

lblResults.Text = added.ToString() + " record inserted.";

}

catch (Exception err)

{

lblResults.Text = "Error inserting record. ";

lblResults.Text += err.Message;

}

finally

{

con.Close();

}

// If the insert succeeded, refresh the author list.

if (added > 0)

{

FillAuthorList();

}

}

protected void cmdUpdate_Click(object sender, EventArgs e)

{

// Define ADO.NET objects.

string updateSQL;

updateSQL = "UPDATE Authors SET ";

updateSQL += "au_fname=@au_fname, au_lname=@au_lname, ";

updateSQL += "phone=@phone, address=@address, city=@city, state=@state, ";

updateSQL += "zip=@zip, contract=@contract ";

updateSQL += "WHERE au_id=@au_id_original";

SqlConnection con = new SqlConnection(connectionString);

SqlCommand cmd = new SqlCommand(updateSQL, con);

// Add the parameters.

cmd.Parameters.AddWithValue("@au_fname", txtFirstName.Text);

cmd.Parameters.AddWithValue("@au_Lname", txtLastName.Text);

cmd.Parameters.AddWithValue("@phone", txtPhone.Text);

cmd.Parameters.AddWithValue("@address", txtAddress.Text);

cmd.Parameters.AddWithValue("@city", txtCity.Text);

cmd.Parameters.AddWithValue("@state", txtState.Text);

cmd.Parameters.AddWithValue("@zip", txtZip.Text);

cmd.Parameters.AddWithValue("@contract", chkContract.Checked);

cmd.Parameters.AddWithValue("@au_id_original", lstAuthor.SelectedItem.Value);

Page 27: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

// Try to open database and execute the update.

int updated = 0;

try

{

con.Open();

updated = cmd.ExecuteNonQuery();

lblResults.Text = updated.ToString() + " record updated.";

}

catch (Exception err)

{

lblResults.Text = "Error updating author. ";

lblResults.Text += err.Message;

}

finally

{

con.Close();

}

// If the updated succeeded, refresh the author list.

if (updated > 0)

{

FillAuthorList();

}

}

}

(OR)

7. a) Explain in detail about single valued data binding and multi valued data binding.

Single value data binding:

Single-value data binding is really just a diffrent approach to dynamic text. To use it, you

add special data-binding expressions into your .aspx files. Thse expressions have the

following format:

<%# expression_goes_here %>

This may look like a script block, but it isn’t. If you try to write any code inside this tag, you

will receive an error. The only thing you can add is a valid data-binding expression. For

example, if you have a public or protected variable named Country in your page, you could

write the following:

<%# Country %>

When you call the DataBind() method for the page, this text will be replaced with the value

for Country (for example, Spain). Similarly, you could use a property or a built-in ASP.NET

object as follows:

<%# Request.Browser.Browser %>

Repeated value data binding:

Although using simple data binding is optional, repeated-value binding is so useful that

almost every ASP.NET application will want to use it somewhere.

6M

Page 28: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Repeated-value data binding works with the ASP.NET list controls . To use repeated-value

binding, you link one of these controls to a data source (such as a field in a data table).

When you call DataBind(), the control automatically creates a full list by using all the

corresponding values. This saves you from writing code that loops through the array or data

table and manually adds elements to a control. Repeated-value binding can also simplify

your life by supporting advanced formatting and template options that automatically

configure how the data should look when it’s placed in the control.

To create a data expression for list binding, you need to use a list control that explicitly

supports data binding.

A Simple List-Binding Example:

List<string> fruit = new List<string>();

fruit.Add("Kiwi");

fruit.Add("Pear");

fruit.Add("Mango");

fruit.Add("Blueberry");

fruit.Add("Apricot");

fruit.Add("Banana");

fruit.Add("Peach");

fruit.Add("Plum");

lstItems.DataSource=fruit; //lstItems is a list control added in .aspx file

this.DataBind();

b) Demonstrate LINQ to objects with an example ASP.NET application.

LINQ to Objects: This is the simplest form of LINQ. It allows you to query collections of in

memory objects. LINQ return an usual type of object, called an iterator object. Although the

iterator object looks like an ordinary collection to your code, it doesn’t hold any

information. LINQ evaluates your expression and quickly grabs the information you need.

This trick is called deferred execution.

Example:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

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

{

protected void Page_Load(object sender, EventArgs e)

{

List<Employee> employees = new List<Employee>();

employees.Add(new Employee(1, "Nancy", "Davolio", "Ms."));

employees.Add(new Employee(2, "Andrew", "Fuller", "Dr."));

6M

Page 29: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

employees.Add(new Employee(3, "Janet", "Leverling", "Ms."));

var matches = from employee in employees

where employee.LastName.StartsWith("D")

select employee;

gridEmployees.DataSource = matches;

gridEmployees.DataBind();

}

public class Employee

{

public int EmployeeID { get; set; }

public string FirstName { get; set; }

public string LastName { get; set; }

public string TitleOfCourtesy { get; set; }

public Employee(int employeeID, string firstName, string lastName,

string titleOfCourtesy)

{

EmployeeID = employeeID;

FirstName = firstName;

LastName = lastName;

TitleOfCourtesy = titleOfCourtesy;

}

}

Note: Give full marks for any valid example.

UNIT IV

8. a) Explain about MVC and its advantages.

ASP.NET MVC is basically a web development framework from Microsoft, which

combines the features of MVC (Model-View-Controller) architecture, the most up-to-date

ideas and techniques from Agile development, and the best parts of the existing ASP.NET

platform.

The MVC architectural pattern separates the user interface (UI) of an application into three

main parts.

The Model − A set of classes that describes the data you are working with as well as the

business logic.

The View − Defines how the application’s UI will be displayed. It is a pure HTML, which

decides how the UI is going to look like.

The Controller − A set of classes that handles communication from the user, overall

application flow, and application-specific logic.

Advantages:

Makes it easier to manage complexity by dividing an application into the model, the

view, and the controller.

Enables full control over the rendered HTML and provides a clean separation of

concerns.

Direct control over HTML also means better accessibility for implementing

compliance with evolving Web standards.

6M

b) Design party invites MVC application.

HOMECONTROLLER.CS

6M

Page 30: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

using partyinvites.Models;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.Mvc;

namespace partyinvites.Controllers

{

public class HomeController : Controller

{

public ViewResult Index()

{

int hour = DateTime.Now.Hour;

ViewBag.Greeting = hour < 12 ? "Goodmorning" : "Goodaftrenoon";

return View();

}

[HttpGet]

public ViewResult Rsvpform()

{

return View();

}

[HttpPost]

public ViewResult Rsvpform(GuestResponse guestResponse)

{

if(ModelState.IsValid)

{

return View("thanks", guestResponse);

}

else

{

return View();

}

}

}

}

MODELS

GUESTRESPONSE.CS

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

namespace PartyInvites.Models

{

public class GuestResponse

{

[Required(ErrorMessage="please enter your naame")]

public String name { get; set;}

Page 31: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

[Required(ErrorMessage="please enter mail id")]

[Regular Expression("+||.+||..+") ErrorMessage="please enter valid email id"]

public String email { get; set; }

[Required(ErrorMessage = "please enter your number")]

public String phone { get; set; }

[Required(ErrorMessage="please specify whether you will attend")]

public bool willattend { get; set; }

}

}

INDEX

@{

Layout = null;

}

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width"/>

<title>Index</title>

</head>

<body>

<div>

@ViewBag.Greeting,World(from the view )

<p>We are going to have an exciting party.<br/>

</p>

@Html.ActionLink("Rsvp Now","RsvpForm")

</div>

</body>

</html>

RSVPFORM

@model partyinvites.Models.GuestResponse

@{

Layout = null;

}

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width" />

<title>RsvpForm</title>

</head>

<body>

@using (Html.BeginForm())

{

@Html.ValidationSummary()

<p>Your name:@Html.TextBoxFor(x => x.name)</p>

<p>Your Email:@Html.TextBoxFor(x => x.Email)</p>

<p>Your phone:@Html.TextBoxFor(x => x.phone)</p>

<p>

Page 32: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Will You [email protected](x => x.WillAttend, new[]

{

new SelectListItem(){Text="Yes i'll be there",Value=bool.TrueString},

new SelectListItem(){Text="no,i can not come",Value=bool.FalseString}

}, "choose an option")

</p>

<input type="submit" value="submit Rsvp" />

}

</body>

</html>

THANKS:

@model partyinvites.Models.GuestResponse

@{

Layout = null;

}

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width" />

<title>Thanks</title>

</head>

<body>

<div>

<h1>Thankyou,@Model.name!</h1>

@if (Model.WillAttend == true)

{

@:Its great that you are coming.The drinks are already in the fridge.

}

else

{

@:sorry to hear that you can not make,but thanks for letting us know.

}

</div>

</body>

</html>

(OR)

9. a) Discuss in detail about WCF service.

WCF stands for Windows Communication Foundation. The elementary feature of WCF is

interoperability. It is one of the latest technologies of Microsoft that is used to build service-

oriented applications. Based on the concept of message-based communication, in which an

HTTP request is represented uniformly, WCF makes it possible to have a unified API

irrespective of diverse transport mechanisms.

Advantages

It is interoperable with respect to other services. This is in sharp contrast to .NET

Remoting in which both the client and the service must have .Net.

WCF services offer enhanced reliability as well as security in comparison to ASMX

(Active Server Methods) web services.

6M

Page 33: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

Implementing the security model and binding change in WCF do not require a major

change in coding. Just a few configuration changes is required to meet the

constraints.

WCF has built-in logging mechanism whereas in other technologies, it is essential to

do the requisite coding.

WCF has integrated AJAX and support for JSON (JavaScript object notation).

It offers scalability and support for up-coming web service standards.

It has a default security mechanism which is extremely robust.

b) Design an application to demonstrate creating and consuming a WCF Web Service.

HelloService.cs

using System.ServiceModel;

namespace HelloService

{

[ServiceContract]

public interface IHelloService

{

[OperationContract]

string GetMessage(string name);

}

}

namespace HelloService

{

public class HelloService : IHelloService

{

public string GetMessage(string name)

{

return "Hello " + name;

}

}

}

Service.cs

using System;

namespace HelloServiceHost

{

class Program

{

static void Main()

{

using(System.ServiceModel.ServiceHost host = new

System.ServiceModel.ServiceHost(typeof(HelloService.HelloService)))

{

host.Open();

Console.WriteLine("Host started @ " + DateTime.Now.ToString());

Console.ReadLine();

}

}

}

6M

Page 34: 14CS505 Hall Ticket Number - becbapatla.ac.inbecbapatla.ac.in/html/scheme/nov2018/CSE_3rd_YEAR_SCHEMES/14CS505.pdf14CS505 Hall Ticket Number: III/IV B.Tech (Regular/Supplementary)

}

Default.aspx

<div style="font-family:Arial">

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:Button ID="Button1" runat="server" Text="Get Message"

onclick="Button1_Click" />

<br />

<asp:Label ID="Label1" runat="server" Font-Bold="true"></asp:Label>

</div>

Note: Designer is also valid

Default.aspx.cs

protected void Button1_Click(object sender, EventArgs e)

{

HelloService.HelloServiceClient client = new

HelloService.HelloServiceClient("BasicHttpBinding_IHelloService");

Label1.Text = client.GetMessage(TextBox1.Text);

}

Note: Give full marks for console application also