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

Asp Net

Uploaded by

KRENA THAKAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Asp Net

Uploaded by

KRENA THAKAR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

assignment1(lab)

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

namespace assignment1_lab_
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblMsg.Text = "Hello World";
lblDate.Text = DateTime.Now.Date.ToString("dd MMMM yyyy");
lblTime.Text = DateTime.Now.Hour.ToString()+":"+
DateTime.Now.Minute.ToString()+":"+DateTime.Now.Second.ToString();

}
}
}

assignment2(lab)

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

namespace assignment2_lab_
{
public partial class WebForm1 : System.Web.UI.Page
{
int a, b;
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(a + b);
}

protected void Button2_Click(object sender, EventArgs e)


{
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(a - b);
}

protected void Button3_Click(object sender, EventArgs e)


{
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(a * b);
}

protected void Button4_Click(object sender, EventArgs e)


{
a = Int32.Parse(TextBox1.Text);
b = Int32.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(a / b);
}
}
}

assignment3(lab)

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

namespace assignment3_lab_
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
int n = Int32.Parse(TextBox1.Text);
int temp ,rem,rev;
temp = n;
rev = 0;
while (n > 0)
{
rem = n % 10;
rev = rev * 10 + rem;
n = n / 10;

}
if (temp == rev)
{
lblMsg.Text = "<b>"+temp + ":" + "is a Palindrome Number"+"</b>";
}
else
{
lblMsg.Text = "<b>"+temp + ":" + "is Not a Palindrome
Number"+"</b>";
}
}
}
}

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

namespace assignment4
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
Label3.Text = "Name:" + TextBox1.Text + "<br>" + "Message:" +
TextBox2.Text;
foreach(ListItem li in CheckBoxList1.Items)
{
if (li.Selected==true && li.Text=="BOLD")
{
Label3.Font.Bold = true;

}
if(li.Selected==false && li.Text == "BOLD")
{
Label3.Font.Bold = false;
}
if (li.Selected == true && li.Text == "ITALIC")
{
Label3.Font.Italic = true;
}
if (li.Selected == false && li.Text == "ITALIC")
{
Label3.Font.Italic = false;
}
if (li.Selected == true && li.Text == "UNDERLINE")
{
Label3.Font.Underline = true;
}
if (li.Selected == false && li.Text == "UNDERLINE")
{
Label3.Font.Underline = false;
}

}
if (RadioButtonList1.SelectedValue=="RED")
{
Label3.ForeColor = System.Drawing.Color.Red;
}
if (RadioButtonList1.SelectedValue == "PINK")
{
Label3.ForeColor = System.Drawing.Color.Pink;
}
if (RadioButtonList1.SelectedValue == "GREEN")
{
Label3.ForeColor = System.Drawing.Color.Green;
}
}
}
}

assignment 5

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

namespace assignment5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
foreach(ListItem li in ListBox1.Items)
{
if (li.Selected == true)
{
TextBox1.Text +="\n" + li.Text;

}
}
}
}
}

assignment 6

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

namespace assignment6
{

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


{

protected void Page_Load(object sender, EventArgs e)


{

protected void Button1_Click(object sender, EventArgs e)


{
string sel = ListBox1.SelectedItem.Text;

if (sel == "cola")
{
Image1.ImageUrl = "images/coca.jpeg";

Label1.Text = "You have to Choosen Cola and its price is Rs.50";


}
else if (sel == "redpop")
{
Image1.ImageUrl = "images/redpop.jpeg";

Label1.Text = "You have to Choosen redpop and its price is Rs.32";


}
else if (sel == "lime")
{
Image1.ImageUrl = "images/lime.jpeg";

Label1.Text = "You have to Choosen lime and its price is Rs.23";


}
else if (sel == "pulpe rain")
{
Image1.ImageUrl = "images/pulp-rain.jpeg";

Label1.Text = "You have to Choosen puple-rain and its price is


Rs.30";
}
}

protected void Button2_Click(object sender, EventArgs e)


{
int quantity = Int32.Parse(TextBox1.Text);
int price=0;
string str = ListBox1.SelectedItem.Text;
if (str == "cola")
{
price = 50;
}
else if (str == "redpop")
{
price = 32;
}
else if (str == "lime")
{
price = 23;
}
else if (str == "pulpe rain")
{
price = 30;
}

int total = quantity*price;

Label3.Text = "You have to pay Rs." + total;


}
}
}

assignment 7

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

namespace assignment_7
{
public partial class WebForm1 : System.Web.UI.Page
{
int cnt = 0;

protected void Page_Load(object sender, EventArgs e)


{
Label3.ForeColor = System.Drawing.Color.Red;
Label3.Text = "0 course(s) Selecetd";

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)


{
foreach (ListItem li in ListBox1.Items)
{
if (li.Selected == true)
{
cnt++;
}

if (cnt == 0)
{
Label3.ForeColor = System.Drawing.Color.Red;
Label3.Text = "0 course(s) Selecetd";
}
else
{
Label3.ForeColor = System.Drawing.Color.Green;
Label3.Text = cnt.ToString() + " Course(s) Seleceted";
}
}

}
protected void CheckBoxList1_SelectedIndexChanged1(object sender, EventArgs
e)
{
ListBox1.Items.Clear();
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected == true)
{
ListBox1.Items.Add(item.Text);
}
}
ListBox1.SelectedIndex = -1;
Label3.ForeColor = System.Drawing.Color.Red;
Label3.Text = "0 course(s) Selecetd";

}
}
}

assignment 8

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

namespace assignment_8
{
public partial class WebForm1 : System.Web.UI.Page
{

protected void Button1_Click(object sender, EventArgs e)


{
if(RadioButtonList1.Text == "Odd or Even")
{
Label2.Visible = true;
TextBox2.Visible = true;
int no=Convert.ToInt32(TextBox1.Text);
if (no % 2 == 0)
{
TextBox2.Text = "No is Even";
}
else
{
TextBox2.Text = "No is Odd";
}

}
if(RadioButtonList1.Text =="Positive or Negative")
{
Label2.Visible = true;
TextBox2.Visible = true;
int no = Convert.ToInt32(TextBox1.Text);
if (no > 0 )
{
TextBox2.Text = "No is Positive";
}
else
{
TextBox2.Text = "No is Negative";
}
}

if(RadioButtonList1.Text == "Square")
{
Label2.Visible = true;
TextBox2.Visible = true;
double no = Convert.ToInt32(TextBox1.Text);
double sqrt;
sqrt = no * no;
TextBox2.Text=Convert.ToString(sqrt);
}

if (RadioButtonList1.Text == "Factorial")
{
Label2.Visible = true;
TextBox2.Visible = true;
double no = Convert.ToInt32(TextBox1.Text);
double fact=1;
for(int i= 1; i <= no; i++)
{
fact = fact * i;
}
TextBox2.Text = Convert.ToString(fact);
}
}

protected void TextBox1_TextChanged(object sender, EventArgs e)


{

protected void TextBox2_TextChanged(object sender, EventArgs e)


{

}
}
}

assignment 11

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

namespace Assignment_11
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
if (FileUpload1.HasFile)
{
string fileExtension =
Path.GetExtension(FileUpload1.FileName).ToLower();
int fileSize = FileUpload1.PostedFile.ContentLength;

// Check if the selected file is an image with a valid extension


and within size limit
if (fileExtension == ".jpg" || fileExtension == ".jpeg")
{
if (fileSize <= 2 * 1024 * 1024) // 2 MB in bytes
{
string filePath = Server.MapPath("~/Uploads/" +
FileUpload1.FileName);
FileUpload1.SaveAs(filePath);

Label1.Text="File Uploaded SuccessFully"; // Hide any


previous error message
Label1.ForeColor = System.Drawing.Color.Green;
}
else
{
Label1.Text = "File size exceeds the allowed limit (2
MB).";
Label1.Visible = true;
Label1.ForeColor = System.Drawing.Color.Red;
}
}
else
{
Label1.Text = "Only JPG or JPEG files are allowed.";
Label1.Visible = true;
Label1.ForeColor = System.Drawing.Color.Red;
}
}
else
{
Label1.Text = "Please select a file to upload.";
Label1.Visible = true;
Label1.ForeColor = System.Drawing.Color.Red;
}
}
}

You might also like