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

Asp_net_C-_unit1

The document outlines a course on Web Application Development using ASP.NET with C#, detailing various practical assignments. These assignments include creating forms with user inputs, handling events, using CSS for styling, and implementing functionality such as user authentication, arithmetic operations, and file uploads. The course emphasizes hands-on coding experience through multiple projects that cover essential ASP.NET concepts and controls.

Uploaded by

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

Asp_net_C-_unit1

The document outlines a course on Web Application Development using ASP.NET with C#, detailing various practical assignments. These assignments include creating forms with user inputs, handling events, using CSS for styling, and implementing functionality such as user authentication, arithmetic operations, and file uploads. The course emphasizes hands-on coding experience through multiple projects that cover essential ASP.NET concepts and controls.

Uploaded by

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

Course Name: Web Application Development using ASP.

NET - C#
Course Code: DSC-M-BCA-245 P
Unit-1: Unit Title: Introduction to .Net Framework, Working with
ASP.NET, Various Controls, Information Passing Methods
P-1: Create a form which takes user name in TextBox control. On the click event of
the button, name of the user and current date & time will be displayed on the title
bar of the web page. (Using Literal control). Also show the use of CSS property to
change the text color of a button control using internal and external CSS.

Step-1: Add Default.aspx

Step-2: Write code on button click event.


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)
{
}
protected void Button1_Click(object sender, EventArgs e)
{

Literal.Page.Title = TextBox1.Text + DateTime.Now;


}
}

Step-3: For Internal Css .


<title>Untitled Page</title>
<style runat="server" type="text/css">
.btnStyle1
{
color:Red;
}
</style>

Step-4: Write Code to add CSSClass in Default.aspx.cs file button click event.
protected void Button1_Click(object sender, EventArgs e)
{

Literal1.Page.Title = TextBox1.Text +" "+ DateTime.Now;


Button1.CssClass = "btnStyle1";

Step-5: For External Css


<head runat="server">
<title>Untitled Page</title>
<style runat="server" type="text/css">
.btnStyle1
{
color:Red;
}
</style>
<link href="StyleSheet.css" rel="Stylesheet" type="text/css" runat="server" />
</head>

Step-6 : Solution Explorer-> Add New Item -> Stylesheet


protected void Button2_Click(object sender, EventArgs e)
{
Button2.CssClass = "btnStyle2";
}

P-2: Take two linkbuttons showing 'New Member' and 'Existing Member'. When
user clicks on the 'New Member link button panell becomes visible, having user
name, password, confirm password and email, city as inputs. When user clicks on
"Existing Member' link button then only panel2 becomes visible having user name
and password as inputs. Set proper property of the textbox to mask the password.
When user inputs in Existing Member matches with user name="Root" and
password="abcd123" then print "Gujarat University" for 5 times, each in a new
row with increasing font size by 1 each time. (Using code render block). Else display
"Invalid user/password".

Step-1: Add New webForm , take two linkButton and set property. And add Two
Panel control . Design as below.

Step-2: Now set Panel1 , Panel2 Visible property false.

Step-3: Write code on linkbutton_click event, and button_click event.


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 U_1p2 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Panel1.Visible = true;

}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Panel2.Visible = true;
}
protected void Button2_Click(object sender, EventArgs e)
{
if (txtuname.Text == "Root" && txtpass.Text == "abcd123")
{
Response.Redirect("CodeRender.aspx");
}
else
{
Response.Write("Invalid Username / Password");
}
}
}

Step-4: Now Add One more page and write code in Source as below:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CodeRender.aspx.cs"
Inherits="CodeRender" %>

<!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>
<% int i;
for(i=1; i<=5;i++)
{ %>
<font size="<%=i %>"> Gujarat University </font>
<br />
<% } %>
</div>
</form>
</body>
</html>

P-3: Design a class file with two methods as sum and subtraction which takes two
arguments. Design a web page to take two integer numbers from the user. When
user clicks on sum or subtraction button, display the result of two entered values in
the label control placed on the web page. (Use of App_code & Bin directory).

Step-1: Add new Asp.net folder APP_CODE. And make Class file in App_code
folder.

Step-2: Write code in class file to make mathods.


using System;
using System.Data;
using System.Configuration;
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;

/// <summary>
/// Summary description for Arithmetic
/// </summary>
public class Arithmetic
{
public Arithmetic()
{
//
// TODO: Add constructor logic here
//
}
public int sum(int a, int b)
{
return a + b;
}
public int subtact(int a, int b)
{
return a - b;
}
}

Step-3: Create web form and design as below:


Step-4: Write code on Button_Click event.
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 U1P3 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Arithmetic obj = new Arithmetic();
int a = Convert.ToInt16( TextBox1.Text);
int b = Convert.ToInt16(TextBox2.Text);
Label1.Text = obj.sum(a, b).ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
Arithmetic obj = new Arithmetic();
int a = Convert.ToInt16(TextBox1.Text);
int b = Convert.ToInt16(TextBox2.Text);
Label1.Text = obj.subtact(a, b).ToString();
}
}

Step- 5: create New -> Project -> ClassLibrary file. Make two methods.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace sum_subtract
{
public class Class1
{
public int Mul(int a, int b)
{
return (a * b);
}
public int Div(int a, int b)
{
return (a / b);
}

Step-6: Build -> Build Solution.

Step-7: Open Existing website and Solution Explorer -> Right Click On Website ->
Add Asp.net folder-> BIN

Step-8: Solution explorer-> Right Click on Bin -> Add reference -> Project -> .dll
File

Step-9: Write code on Button Click event.


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 U1P3 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button3_Click(object sender, EventArgs e)


{
sum_subtract.Class1 obj1 = new sum_subtract.Class1();
int a = Convert.ToInt16(TextBox1.Text);
int b = Convert.ToInt16(TextBox2.Text);
Label1.Text = obj1.Mul(a, b).ToString();

}
protected void Button4_Click(object sender, EventArgs e)
{
sum_subtract.Class1 obj1 = new sum_subtract.Class1();
int a = Convert.ToInt16(TextBox1.Text);
int b = Convert.ToInt16(TextBox2.Text);
Label1.Text = obj1.Div(a, b).ToString();

}
}

P-4: Create a RadioButtonList that displays the names of some colors in two
columns. Add a button to the web form which when clicked changes the background
color of the form to the color selected from the list. Also show the use of external
CSS file.

Step-1: Add a web form . In web form Add Radiobuttonlist control and button
control.

Step-2: set the property of RadiobuttonList control is Items and Repeat columns=2.

Step-3: Now write code on button click event.


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 U1P4 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btncolor_Click(object sender, EventArgs e)
{
Response.Write("<body bgcolor="+RadioButtonList1.SelectedItem.Text+">");
}
}

P-5: Create a web page having checkboxlist control shows different products. Web
page should have a button and a label. On the click event of the button shows the
message "Thank You for placing the order of following items" and then list of all
products selected by the user from the checkboxlist server control. Each selected
product should be displayed in the new line.

Step-1: add new web form and add Checkboxlist control, Button and label control.

Step-2: Write Code on button click event.


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 U1p5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
string pro = "";
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected == true)
{
pro += CheckBoxList1.Items[i].Text + "<br>";
}
}
Label1.Text = "Thank you for Placing your order<br><br>" + pro;
}
}

P-6: Accept Item No, Item Name, Item Price, Item Quantity. Store information in
cookie. Display stored information in next page with Total Price = Price * Quantity.

Step-1: add web form and create as below:

Step-2: write code on button_click event.


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 U1p6 : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie ck = new HttpCookie("mycookie");
ck["no"] = txtino.Text;
ck["name"] = txtiname.Text;
ck["price"] = txtprice.Text;
ck["qty"] = txtqty.Text;

Response.Cookies.Add(ck);
Response.Redirect("U1p6next.aspx");

}
}

Step-3: create another web form and design as below:

Step-4: write code on page load event for retrieve cookie .


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 U1p6next : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie reqck = Request.Cookies["mycookie"];
if (reqck != null)
{
lblino.Text = reqck["no"];
lbliname.Text = reqck["name"];
lbliprice.Text = reqck["price"];
lbliqty.Text = reqck["qty"];
int total = Convert.ToInt16(lbliprice.Text) *
Convert.ToInt16(lbliqty.Text);
lbltotal.Text = Convert.ToString(total);
}
}
}

P-7: Take single image having 3 rectangle shapes horizontally having text "Home",
"Product" and "Services" written in the boxes. When user clicks on the first
rectangle Home.aspx page should be opened. Similarly, when user clicks on the
Product rectangle the product.aspx and Service rectangle then service.aspx should
be opened. Use ImageMap control..

Step-1: Make image in paint as below:

Step-2: now add web form and add Imagemap control set imageurl property

Step-3: Now set rectangle Hotspots property.


P-8:. Using AdRotator control, display 3 images of car and when user clicks on it,
open website of it. Load the advertisement details from the XML.

Step-1: Add xml file in website. And make advertisement file.


<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/images/car1.jpg</ImageUrl>
<AlternateText>Car1</AlternateText>
<NavigateUrl>http://www.google.com</NavigateUrl>
</Ad>
<Ad>
<ImageUrl>~/images/car2.jpg</ImageUrl>
<AlternateText>Car2</AlternateText>
<NavigateUrl>http://www.google.com</NavigateUrl>
</Ad>
<Ad>
<ImageUrl>~/images/car3.jpg</ImageUrl>
<AlternateText>Car3</AlternateText>
<NavigateUrl>http://www.google.com</NavigateUrl>
</Ad>
</Advertisements>
Step-2: add new web form and take adrotator control.

Step-3: Now choose xml file data source.

Step-4: select xml file in xml data source.


P-9:. Write code to upload only image files (.bmp, .jpg, .gif) and less than 1 kb in
folder "Image-Folder". Also display uploaded image files on the same web page
using datalist control.

Step-1: Add a web form and File upload control and button .

Step-2: Add data List control from Toolbox -> Data.


Step-2: Solution Explorer -> Rigth click on Website -> add a folder-> images

Step-3: Now image control edit Data binding and write code
Eval("Name","~/images /{0}") as shown below:
Step-4: Write code on button_click event.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(Server.MapPath("~/images/"));
DataList1.DataSource = di.GetFiles();
DataList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
String s = Server.MapPath("~/images/") + FileUpload1.FileName;
if (s.EndsWith(".jpg") || s.EndsWith(".png") || s.EndsWith(".gif") &&
FileUpload1.FileBytes.Length <= 2048)
{

FileUpload1.SaveAs(s);
Response.Write("File Uploaded");

}
else
{
Response.Write("Upload Images only .jpg, .png, .gif");
}

}
else
{
Response.Write("File Is not Uploaded");
}
}
}

P-10:. Create a form to display total number users visited a website.

Step-1: create a Global.asax page and write code as below:


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

<script runat="server">

void Application_Start(object sender, EventArgs e)


{
// Code that runs on application startup

Application["visitor"] = 0;
}

void Application_End(object sender, EventArgs e)


{
// Code that runs on application shutdown

void Application_Error(object sender, EventArgs e)


{
// Code that runs when an unhandled error occurs

void Session_Start(object sender, EventArgs e)


{
// Code that runs when a new session is started
Application.Lock();
Application["visitor"] = (int)Application["visitor"] + 1;
Application.UnLock();
}

void Session_End(object sender, EventArgs e)


{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
Application.Lock();
Application["visitor"] =(int)Application["visitor"] - 1;
Application.UnLock();

</script>

Step-2: Now add new web form and add label control in it.

Step-3: write code on page_load event.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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


{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "You have visited this website " + Application["visitor"].ToString() + "
times";

}
}

You might also like