0% found this document useful (0 votes)
52 views15 pages

Using Using Using Using Using Using Namespace Public Partial Class Protected Void Object If True True True

The document describes code for validating user input on a web form. When the form loads, it makes textboxes and labels invisible. When the submit button is clicked, it checks if the user, email, and address textboxes are empty. If empty, it displays error messages next to the fields. If not empty, it displays the input on the results label along with making the error messages invisible. It also includes a clear button to reset the form fields and hide the results.

Uploaded by

Kristen Torres
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views15 pages

Using Using Using Using Using Using Namespace Public Partial Class Protected Void Object If True True True

The document describes code for validating user input on a web form. When the form loads, it makes textboxes and labels invisible. When the submit button is clicked, it checks if the user, email, and address textboxes are empty. If empty, it displays error messages next to the fields. If not empty, it displays the input on the results label along with making the error messages invisible. It also includes a clear button to reset the form fields and hide the results.

Uploaded by

Kristen Torres
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

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

WebControls; namespace Homework1 { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { Userl.Visible = true; Emaill.Visible = true; Addl.Visible = true; } } protected void Button1_Click(object sender, EventArgs e) { if (T1.Text == "") { Userl.Text = "enter the user name"; } if (T3.Text == "") { Emaill.Text = "enter the email"; } if (T4.Text == "") { Addl.Text = "enter the address"; } else { Gl.Visible = true; Gl.Text = "user name is " + T1.Text + "</br>"; Gl.Text = "Email is "+ Gl.Text + T3.Text + "</br>"; Gl.Text = "Address is " + Gl.Text + T4.Text; Userl.Visible = false; Emaill.Visible = false; Addl.Visible = false;

} } protected void Button2_Click(object sender, EventArgs e) { T1.Text = ""; T3.Text = ""; T4.Text = ""; Userl.Visible = false; Emaill.Visible = false; Addl.Visible = false; Gl.Visible = false;

} } } After Submitting :

If we don't filled the values :

2) using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Homework1 { public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (T1.Text == "" || T2.Text == "") { Errorl.Text = "please enter the numbers"; Errorl.Visible = true; } else { int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); int c = a + b; Rl.Text = c.ToString(); Rl.Visible = true;

Rld.Visible = true; Errorl.Visible = false; } } protected void Button2_Click(object sender, EventArgs e) { if (T1.Text == "" || T2.Text == "") { Errorl.Text = "please enter the numbers"; Errorl.Visible = true; } else { int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); int c = a - b; Rl.Text = c.ToString(); Rl.Visible = true; Rld.Visible = true; Errorl.Visible = false; } } protected void Button3_Click(object sender, EventArgs e) { if (T1.Text == "" || T2.Text == "") { Errorl.Text = "please enter the numbers"; Errorl.Visible = true; } else { int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); int c = a * b; Rl.Text = c.ToString(); Rl.Visible = true; Rld.Visible = true; Errorl.Visible = false; } }

protected void Button4_Click(object sender, EventArgs e) { if (T1.Text == "" || T2.Text == "") { Errorl.Text = "please enter the numbers"; Errorl.Visible = true; } else { int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); int c = a / b; Rl.Text = c.ToString(); Rl.Visible = true; Rld.Visible = true; Errorl.Visible = false; } } protected void clr_Click(object sender, EventArgs e) { T1.Text = ""; T2.Text = ""; Rl.Text = ""; Rld.Visible = false; Errorl.Visible = false; }

} } When page loads :

When the user doesn't enter the numbers :

After Entering the numbers pressing the buttons here, I click the multiplication one:

3)

dll file:

using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Homework1 { public class Cal { public int add(int a, int b) { return a + b; } public int sub(int a, int b) { return a - b; } public int mul(int a, int b) { return a * b; } public int div(int a, int b) { return a / b; } } }

Aspx.cs using DLL using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Homework1; namespace Homework1 { public partial class WebForm3 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Cal c = new Cal(); int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); T3.Text = c.add(a, b).ToString(); } protected void Button2_Click(object sender, EventArgs e) { Cal c = new Cal(); int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); T3.Text = c.sub(a, b).ToString(); } protected void Button3_Click(object sender, EventArgs e) { Cal c = new Cal(); int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); T3.Text = c.mul(a, b).ToString(); } protected void Button4_Click(object sender, EventArgs e)

{ Cal c = new Cal(); int a = Convert.ToInt32(T1.Text); int b = Convert.ToInt32(T2.Text); T3.Text = c.div(a, b).ToString(); } protected void clr_Click(object sender, EventArgs e) { T1.Text = ""; T2.Text = ""; T3.Text = ""; } } } When page loads :

When the user enter the numbers and press the add button :

4)

VERIFYING THE EMAIL

using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Homework1 { public partial class WebForm4 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } private void ValidateEmail() { string email = T1.Text; Regex regex = new Regex(@"^([\w\.com\-]+)@([\w\-]+)((\.(\w){2,3})+)$"); Match match = regex.Match(email); if (match.Success) { L1.Text = email + " is Valid Email Address"; } else { L1.Text = email + " is Invalid Email Address"; } }

protected void Button1_Click(object sender, EventArgs e) { ValidateEmail(); }}} When user gives the two @@ symbols it shows as invalid :

5) using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing.Text; namespace Homework1 { public partial class WebForm5 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void B1_Click(object sender, EventArgs e) { DD1.Items.Add("India"); DD1.Items.Add("USA"); DD1.Items.Add("AUS"); DD1.Items.Add("Africa"); } protected void B2_Click(object sender, EventArgs e) { DD1.Items.Clear(); } protected void B3_Click(object sender, EventArgs e) {

ListItem _lstitemTemp = new ListItem(T1.Text); if (DD1.Items.Contains(_lstitemTemp)) { L1.Text = "THE COUNTRY NAME IS EXISTS IN DROPDOWN"; L1.ForeColor = System.Drawing.Color.ForestGreen; L1.Visible = true; } else { L1.Text = "THE COUNTRY NAME IS NOT EXISTS IN DROPDOWN";

L1.ForeColor = System.Drawing.Color.Red; L1.Visible = true; } } protected void B4_Click(object sender, EventArgs e) { int a = Convert.ToInt32 (DD1.Items.Count); L1.Text = a.ToString(); L1.Visible = true; } protected void Button5_Click(object sender, EventArgs e) { foreach (ListItem li in DD1.Items) { DD2.Items.Add(li); } }

} }

When Page Loads :

When user clicks the load countries button

when the user clicks the does country exists button , if exists it show in green color , if not in red color:

When the user clicks the show number drop down it shows 4 in green color:

When the user clicks the load items from drop down1 it shows all the drop down 1 items in drop down2:

You might also like