Asp_net_C-_unit1
Asp_net_C-_unit1
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-4: Write Code to add CSSClass in Default.aspx.cs file button click event.
protected void Button1_Click(object sender, EventArgs e)
{
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.
}
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" %>
<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.
/// <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;
}
}
}
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-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
}
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.
}
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.
}
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.
}
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");
}
}
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-2: now add web form and add Imagemap control set imageurl property
Step-1: Add a web form and File upload control and button .
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;
FileUpload1.SaveAs(s);
Response.Write("File Uploaded");
}
else
{
Response.Write("Upload Images only .jpg, .png, .gif");
}
}
else
{
Response.Write("File Is not Uploaded");
}
}
}
<script runat="server">
Application["visitor"] = 0;
}
</script>
Step-2: Now add new web form and add label control in it.
}
}