View

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 22

1. Write an Asp.Net Program to print a Message on web form.

View :

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

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


{
protected void Page_Load(object sender, EventArgs e)
{
MessageLabel.Text = "WELCOME TO THE WEB FORMS";
}
}

Output :
2. Write an Asp.Net Program to Create Simple Web Application using two or more web
form.
View :
 First web form

 Second web form

code :

 First web form


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

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


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

}
protected void tnsubmit_Click(object sender, EventArgs e)
{
Response.Redirect("~/Second.aspx");
}
protected void btnsubmit1_Click(object sender, EventArgs e)
{
Server.Transfer("~/Second.aspx");
}
}

 Second web form


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Second : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (PreviousPage != null && PreviousPage.IsPostBack)
{
TextBox txtunm = (TextBox)PreviousPage.FindControl("txtname");
lblname.Text = "Welcome" + " " + txtunm.Text;
}
}
}

Output :
3. Write an Asp.Net program using while or for loop to print sum of first 100 ODD and Even
Numbers.
View :

code :
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)
{
int oddSum = 0;
for (int i = 1; i <= 200; i += 2) // Increment by 2 to get odd numbers
{
oddSum += i;
}

// Calculate sum of the first 100 even numbers


int evenSum = 0;
for (int i = 2; i <= 200; i += 2) // Increment by 2 to get even numbers
{
evenSum += i;
}

// Display the sums on the page


lblOddSum.Text += oddSum.ToString();
lblEvenSum.Text += evenSum.ToString();
}
}

Output :
4. Write an Asp.Net Program to add the value of Text Box in to Dropdown List and List box
Controls.
View :

Add button code :


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)
{

DropDownList1.DataSource = new List<string> { " " };


DropDownList1.DataBind();
}
}

protected void Button1_Click1(object sender, EventArgs e)


{
string textBoxValue = TextBox1.Text.Trim();

if (!string.IsNullOrEmpty(textBoxValue))
{

DropDownList1.Items.Add(new ListItem(textBoxValue));

ListBox2.Items.Add(textBoxValue);

TextBox1.Text = string.Empty;
}
}
}

Delete button code :

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 ddlItems_SelectedIndexChanged(object sender, EventArgs e)
{
// Handle DropDownList selection change if needed
}
protected void btnDeleteFromDropDown_Click(object sender, EventArgs e)
{
// Delete selected item from DropDownList
if (ddlItems.SelectedIndex != -1)
{
ddlItems.Items.RemoveAt(ddlItems.SelectedIndex);
}
}
protected void btnDeleteFromListBox_Click(object sender, EventArgs e)
{
// Delete selected items from ListBox
for (int i = lstItems.Items.Count - 1; i >= 0; i--)
{
if (lstItems.Items[i].Selected)
{
lstItems.Items.RemoveAt(i);
}
}
}
}
Output :
5. Write an Asp.Net Program to set Image on Image Control according to selection of image
name from Dropdown list.
View :

code :
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)
{
// Set default image on page load
DisplayImage("image1.jpg");
}
}
protected void ddlImageNames_SelectedIndexChanged(object sender, EventArgs e)
{
// Display the selected image
string selectedImage = ddlImageNames.SelectedValue;
DisplayImage(selectedImage);
}

private void DisplayImage(string imageName)


{
// Set the ImageUrl property of the Image control to display the selected image
imgDisplay.ImageUrl = "~/Images/{imageName}"; // Assuming images are in the "Images"
folder
}
}
Output :
6. Write an Asp.Net Program to demonstrate use of Master Page.
View :

Code :
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="home2.master.cs"
Inherits="home2" %>

<!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></title>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<style type="text/css">
.style1 {
width: 100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">

<table class="style1">
<tr>
<td colspan="2" height="150px" align="center" bgcolor="#CC33FF">
<b> YASHWANTRAO CHAVAN MAHAVIDYALAYA</b></br>
URUN-ISLAMPUR</td>

</tr>
<tr>
<td colspan="2">
<asp:Menu ID="Menu1" runat="server" Orientation="Horizontal">
<Items>
<asp:MenuItem NavigateUrl="~/aboutus.aspx" Text="about us" Value="about us">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="~/contact.aspx" Text="contact us" Value="contact us">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="~/registration.aspx" Text="registration"
Value="registration"></asp:MenuItem>
<asp:MenuItem NavigateUrl="~/photo.aspx" Text="photo" Value="photo">
<asp:MenuItem NavigateUrl="~/sports.aspx" Text="sports" Value="sports">
</asp:MenuItem>
<asp:MenuItem NavigateUrl="~/annualfunction.aspx" Text="annual function"
Value="annual function"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem></asp:MenuItem>
</Items>
</asp:Menu>
</td>

</tr>
<tr>
<td colspan="2">
&nbsp;</td>

</tr>
<tr>
<td height="200px" width="30%">
NEWS AND EVENTS</td>
<td>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

</asp:ContentPlaceHolder>
</div>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<b> developed by sanika</b></td>

</tr>
</table>

</form>
</body>
</html>

Output :

About us page :
Contact page :
7. Program to demonstrate client side state management and Server side management.
View :
 Client side management

Code :
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)
{
// Check if the cookie exists
if (Request.Cookies["userName"] != null)
{
// If the cookie exists, set the TextBox value and display a greeting
txtName.Text = Request.Cookies["userName"].Value;
lblGreeting.Text = "Welcome back, " + txtName.Text + "!";
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("userName", txtName.Text);
Response.Cookies.Add(cookie);
lblGreeting.Text = "Hello, " + txtName.Text + "!";
}
}
Output :
 server side state management

code :
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)
{
// Check if the Session variable exists
if (Session["userName"] != null)
{
// If the Session variable exists, set the TextBox value and display a greeting
txtName.Text = Session["userName"].ToString();
lblGreeting.Text = "Welcome back, " + txtName.Text + "!";
}
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
Session["userName"] = txtName.Text;
lblGreeting.Text = "Hello, " + txtName.Text + "!";
}
}
Output :
10. Write an Asp.Net Program to perform Insert, update delete operation in Database.
View :

code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

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


{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=F:\
rohini2023\WebSite3\App_Data\college.mdf;Integrated Security=True;User Instance=True");
SqlCommand cmd;
String s;
int i;
SqlDataAdapter da;
DataTable dt;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{

}
protected void btnsave_Click(object sender, EventArgs e)
{
con.Open();
s = "insert into studentinfo(rollno,sname,sclass,smob,semail)values('" + Txtroll.Text + "','" +
Txtname.Text + "','" + Txtclass.Text + "','" + Txtmob.Text + "','" + txtemail.Text + "')";
cmd = new SqlCommand(s, con);
i = cmd.ExecuteNonQuery();
if (i > 0)
{
lblmsg.Text = "record save";
}
else
{
lblmsg.Text = "record not save";
}
con.Close();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
con.Open();
s = "update studentinfo set sname='" + Txtname.Text + "', sclass='" + Txtclass.Text + "', smob='"
+ Txtmob.Text + "', semail='" + txtemail.Text + "' where rollno=" + Txtroll.Text + "";
cmd = new SqlCommand(s, con);
i = cmd.ExecuteNonQuery();
cmd.ExecuteReader();
if (i > 0)
{
lblmsg.Text = "record update";
}
else
{
lblmsg.Text = "record not update ";
}
con.Close();
}
protected void btndelete_Click(object sender, EventArgs e)
{
con.Open();
s = "delete from studentinfo where rollno='" + Txtroll.Text + "'";
cmd = new SqlCommand(s, con);
i = cmd.ExecuteNonQuery();
if (i > 0)
{
lblmsg.Text = "record delete";
}
else
{
lblmsg.Text = "record not delete";
}
con.Close();
}
protected void btndisplay_Click(object sender, EventArgs e)
{
s = "select * from studentinfo where sclass='"+Txtclass .Text +"' ";
da = new SqlDataAdapter(s, con);
dt = new DataTable();

da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
//con.Open();
//s = "select count(*) from studentinfo ";
//cmd = new SqlCommand(s, con);
//i = Convert.ToInt16(cmd.ExecuteScalar());
//Response.Write(i);
//con.Close();
}

protected void btnsearch_Click(object sender, EventArgs e)


{
s = "select * from studentinfo where rollno='" + txtroll.Text + "'";
da = new SqlDataAdapter(s, con);
dt = new DataTable();
da.Fill(dt);
Txtname.Text = dt.Rows[0][1].ToString();
Txtclass.Text = dt.Rows[0][2].ToString();
Txtmob.Text = dt.Rows[0][3].ToString();
txtemail.Text = dt.Rows[0][4].ToString();

}
}

Output :

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy