• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Student assignment
 

Student assignment

on

  • 508 views

 

Statistics

Views

Total Views
508
Views on SlideShare
508
Embed Views
0

Actions

Likes
1
Downloads
13
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Student assignment Student assignment Document Transcript

    • 1)How to add two numbers in ASP.NETprotected void Button1_Click(object sender, EventArgs e) {int a = int.Parse(TextBox1.Text);int b = int.Parse(TextBox2.Text);int sum = a + b; Label1.Text = "Sum Of Digits :" + a.ToString() + " And " + b.ToString() + " =" + sum.ToString(); Label2.Visible = false; TextBox1.Visible = false; TextBox2.Visible = false; Button1.Visible = false; }OUTPUT:2)How To Add Item at Run Time in Dropdownlistand get the Index and text of it. add item at run time get Index of dropdown list items get text of dropdown listprotected void Page_Load(object sender, EventArgs e) {if (!IsPostBack) {DropDownList1.Items.Add("Add");DropDownList1.Items.Add("Subtract");DropDownList1.Items.Add("Multiplication");DropDownList1.Items.Add("Division"); } }protected void Button1_Click(object sender, EventArgs e) { TextBox1.Text = DropDownList1.SelectedItem.Text; }protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { TextBox1.Text = DropDownList1.SelectedIndex.ToString(); }
    • 3)How To add or Remove selected item from ListBox add selected item in listbox OUTPUT Remove selected item from Listbox OUTPUTprotected void Button1_Click(object sender, EventArgs e) {for (int i = 0; i < ListBox1.Items.Count; i++) {if (ListBox1.Items[i].Selected) {ListBox2.Items.Add(ListBox1.Items[i].Text); } } }protected void Button2_Click(object sender, EventArgs e) {ListBox2.Items.Remove(ListBox2.SelectedItem.Text); }4)AddCheckboxlist Item In TextBox Select an item from checkboxlixt OUTPUTprotected void Button1_Click(object sender, EventArgs e) {for (int i = 0; i < CheckBoxList1.Items.Count; i++) {if (CheckBoxList1.Items[i].Selected) {if (TextBox1.Text == "") { TextBox1.Text = CheckBoxList1.Items[i].Text; }else TextBox1.Text = CheckBoxList1.Items[i].Text + " ," + TextBox1.Text; } } }
    • 5)How To Split Text From any string and stored it in listbox Items When you click on the button split then whole string is split and add these words in listbox.protected void Button1_Click(object sender, EventArgs e) {stringstr = TextBox1.Text;string[] arr1 = str.Split(new char[] { });string z = "";for (int i = 0; i < arr1.Length; i++) { z = arr1[i];ListBox1.Items.Add(z.ToString()); } }6)How To Upload an Image On Server and display it after Uploading Please ensure that permissions for Writing data is Allow on the Folder where youwant to upload pictures. And set the PostBackurl property of Upload button is “~/yourpage.aspx”.protected void Button1_Click(object sender, EventArgs e) {if (FileUpload1.HasFile) {string d = System.IO.Path.GetExtension(FileUpload1.FileName);if (d == ".jpg" || d == ".JPG" || d == ".JPEG") {string path = "~/Upload/";string path2 = Server.MapPath(path);FileUpload1.SaveAs(path2 + FileUpload1.FileName); // Response.Write("<script>alert(File Have Been Successfully Uploaded to the Server)</script>"); Image1.ImageUrl = "~/Upload/" + FileUpload1.FileName; } }
    • 7)How To calculate The Age From Date Of BirthInput The date In mm/dd/yyyy format and it produces the result as:public static intdd;public static intee;protected void Page_Load(object sender, EventArgs e) { }protected void Button1_Click(object sender, EventArgs e) {DateTimeaa = DateTime.Today;DateTime bb = Convert.ToDateTime(TextBox3.Text);int cc= aa.Year - bb.Year;dd = DateTime.Now.Month;ee = bb.Month;if (dd<ee) {dd =dd + 12; cc = cc - 1;int mm1 = dd - ee; TextBox4.Text = mm1.ToString(); TextBox2.Text=cc.ToString(); }else{int mm2 = dd - ee; TextBox2.Text = cc.ToString(); TextBox4.Text = mm2.ToString();} }8)How To Convert “536” into Five Hundred three six onlypublic static string ss1;protected void Page_Load(object sender, EventArgs e)
    • { }protected void Button1_Click(object sender, EventArgs e) {int d =TextBox1.Text.Count();int c = Convert.ToInt32(TextBox1.Text);if (d == 3) {int first = c % 100;int second = c / 100;int third = first / 10;int fourth = first % 10; TextBox2.Text = sw(second)+"Hundred"+" "+sw(third)+" "+sw(fourth)+"Only"; }if (d == 2) {int mm1 = c / 10;int mm2 = c % 10; TextBox2.Text = sw(mm1) + " " + sw(mm2)+"Only"; }if (d == 1) {int mm3 = c % 10; TextBox2.Text = sw(mm3) + "Only"; } }public string sw(intaa) {switch (aa) {case 0: ss1 = "Zero";break;case 1: ss1 = "One";break;case 2: ss1 = "Two";break;case 3: ss1 = "Three";break;case 4: ss1 = "Four";break;case 5: ss1 = "Five";break;case 6: ss1 = "Six";break;case 7: ss1 = "Seven";break;case 8: ss1 = "Eight";
    • break;case 9: ss1 = "Nine";break;default:break; }return ss1; }9) How to add Image Captcha Control in Asp.net PageStep a)You must have to attach Mscaptcha control in your toolbox.Step b)Add MsCaptcha Control in your page , One TextBox, one label and one Button as shown in figure.Step c)Add code in on button click event..protected void Button1_Click(object sender, EventArgs e) {CaptchaControl1.ValidateCaptcha(TextBox1.Text);if (!CaptchaControl1.UserValidated) Label1.Text = "Input is incorrect";else Label1.Text = "Correct Input"; }Step d)open web.config file and made changes carefully</system.web><system.webServer><handlers><add name="MSCaptcha.captchaImageHandler" verb="GET" path="CaptchaImage.axd"type="MSCaptcha.captchaImageHandler, MSCaptcha" resourceType="Unspecified" /></handlers></system.webServer>