ASP .Net Practicals-SEM-5
ASP .Net Practicals-SEM-5
<div>
</div>
</form>
Output :
using System;
namespace MyProgram
MyNamespace.SampleClass.myMethod();
namespace MyNamespace
{
Console.WriteLine("Creating my namespace");
Output :
Step 1 – Open the Visual Studio –> Create a new empty Web application.
Step 2 – Create two New web page one for display hyperlink and other for navigate to it.
Step 3 – Drag and drop HyperLink control on web page from Toolbox.
</div>
</form>
Output :
4. Write a Program to Demonstrate Request, Response and Server Object.
<div>
</div>
</form>
Label2.Text = Server.UrlDecode(Request.Url.ToString());
Output:
5. Write a Program using delegate in which addition and substraction of two Interger
value Possible.
using System;
class Program
Console.WriteLine(addDelegate(5, 2));
Console.WriteLine(subDelegate(5, 2));
class Calculation
{
public static int add(int n1, int n2)
return n1 + n2;
return a - b;
Output :
6. Write a program using while or for loop to print sum of first 100 ODD and Even
Numbers.
using System;
namespace SumOfOdd_Even
class Program
// Calling Functions..
sumOfOdd();
sumOfEven();
}
// Function for Sum of First 100 Odd Integers.
if (count % 2 != 0)
count++;
if (count % 2 == 0){
count++;
}
Output :
using System;
namespace Basics
class Program
{
Console.WriteLine(i);
Output :
8. Write a program to Create Simple Web Application using two or more web form.
Web-Form-1.aspx
<br/>
Web-Form-2.aspx
<div>
</div>
Web-Form-3.aspx
<div>
<div>
</div>
</form>
Output :
10. Write a program to add the value of Text Box in to Dropdown List and List box
Controls.
<div>
<asp:ListItem>Value 1</asp:ListItem>
<asp:ListItem>Value 2</asp:ListItem>
<asp:ListItem>Value 3</asp:ListItem>
</asp:DropDownList>
<br />
<asp:ListBox ID="ListBox1" runat="server">
</asp:ListBox>
</div>
</form>
Code-Behind :
DropDownList1.Items.Add("New Added");
ListBox1.Items.Add("New Added");
Output :
11. Write a program to Delete Items from Dropdown list and List box.
<form id="form1" runat="server">
<div>
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
</asp:DropDownList>
<br />
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
</asp:ListBox>
<br />
</div>
</form>
Code-Behind :
DropDownList1.Items.RemoveAt(DropDownList1.Items.IndexOf(DropDownList1.SelectedItem));
{
ListBox1.Items.RemoveAt(ListBox1.Items.IndexOf(ListBox1.SelectedItem));
Output :
12. Write a program to set Image on Image Control according to selection of image name
from dropdown list.
Web-Form :
<div>
</asp:DropDownList>
<hr />
</div>
</form>
Code-Behind :
string id = ddlImages.SelectedItem.Value;
Image1.Visible = id != "0";
if (id == "1")
Image1.ImageUrl = "images/image1.jpg";
if (id == "2")
Image1.ImageUrl = "images/image2.jpg";
if (id == "3")
Image1.ImageUrl = "images/image3.jpg";
Output :
<div>
<br />
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
runat="server" ControlToValidate="txtEmail" ErrorMessage="*" ForeColor="Red"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">Invalid
Email!</asp:RegularExpressionValidator>
<br />
</div>
</form>
Output :
14. Write a program which is use different Rich Control.
<div>
<br />
<br />
</asp:MultiView>
</div>
</form>
Output :
<div>
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<Items>
</Items>
</asp:Menu>
</div>
</form>
Output :
<div>
<asp:TreeView ID="TreeView1" runat="server">
<Nodes>
</asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
</div>
</form>
Output :
Step 1: Add Four web forms to the application named Default.aspx Sem1.aspx and Sem2.aspx
Sem3.aspx by performing the following steps:
Move to the Solution Explorer window
Right-click on the application name and select the Add New Item option from the context
menu
Name the web form as Defalult.aspx and click the Add button
Step 2: Similarly add the Sem1.aspx, Sem2.aspx, Sem3.aspx and Clang.aspx web form to the
application. After that we have to add the Site Map file into the project.
The Site Map file is the XML file and has the extension .sitemap. The steps are as
follows.
Step 3: Right-click the application in the Solution Explorer window and then click the
Add New Item option from the context menu.
Step 4: Select the Site Map Template from the Templates Pane. Note that, by default, the
file has the name web.sitemap.
</siteMapNode>
</siteMapNode>
Step 5: Now Add one SiteMapPath control on the Default.aspx page from the navigation tab
of the toolbox.
Step 6: Now Add one SiteMapPath control on the All pages from the navigation tab of the
toolbox.
Output :
18. Write a program to demonstrate use of Master Page and Theme.
Master Page :-
Step 1 : Create a new project using "File" -> "New" -> "Project..." then select web
"ASP.NET Web Forms Application". Name it "MasterPageDemo".
Step 2 : Go to Solution Explorer then right-click on your application then select "Add
New Item" then select "Master Page" and name it “Site.Master”.
Step 3 : Now, go to Solution Explorer then right-click on your application then select
"Add New Item" then select "Web form using Master Page" and name it “Home.aspx”. Next add
click.
Step 4 : Now, select a Master Page; just click "OK" and Edit like below.
<div>
</div>
<br />
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<br />
</div>
</div>
</form>
Step 5 : Now add Web Form with Master Page and Edit.
Output :
Theme :
Step 1 : Go to Solution Explorer then right-click on your application then select "Add
New Item" then select "Skin File and add this.
Step 2 : Add New Web Form and add StylesheetTheme="SkinFile" in <Page> tag.
<br />
<br />
Step 3 : Now to an new Label, Textbox and Button and edit SkinID Properties.
Output :
<div>
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name"
SortExpression="Name" />
</Columns>
</asp:GridView>
<br />
<br />
</div>
</form>
<div>
<Fields>
</Fields>
</asp:DetailsView>
</form>
Code-Behind :
using System.Data;
using System.Data.SqlClient;
conn.Open();
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE tbl_user SET Name='" + txtName.Text + "', Email='" +
txtEmail.Text + "', Contact='" + txtContact.Text + "' WHERE Name='"+txtName.Text+"'";
cmd.Connection = conn;
cmd.ExecuteNonQuery();
Code-Behind btnDelete:
cmd.CommandType = CommandType.Text;
cmd.Connection = db;
cmd.ExecuteNonQuery();
23. Write a program to display the records from database using Data Reader Object.