Your SlideShare is downloading. ×
Student assignment
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Student assignment

538
views

Published on


0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
538
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. 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(); }
  • 2. 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; } } }
  • 3. 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; } }
  • 4. 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)
  • 5. { }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";
  • 6. 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>