Practical - 02
AIM: Design a web application to add two integer numbers using ASP.Net through C# language.
How to open Visual Studio
- Click on Start Button.
- Search Microsoft Visual Studio 2008.
- Click on File Menu --> New --> WebSite --> Select ASP.NET Website --> Select Location and Language (Should be Visual C#) --> OK
Framework Introduction
Figure 1: Introduction of Visual Studio Framework.
Different Windows in Visual Studio
Solution Explorer: Solution Explorer is a window which shows all the items in your project solution. (Items like all projects, classes, folders etc).
- To view solution explorer window, from the view menu, select Solution Explorer. (View --> Solution Explorer)
- Visual studio organizes applications into projects and solutions. The solution file will have a .sln extension and the project file will have .csproj or .vbproj.
- Startup Project in solution explorer is bolded. To change your startup project, Right click the project, & select “Set as Startup Project”.
ToolBox: To view the toolbox, select toolbox from the view menu
Proporties Window: Property window is used to change the property of a web form or a control in web form. To view the property window, select property window in view menu.
Web Form: Web form has the extension of .aspx.
- A Web Form also has a code behind and designer files.
- Code behind file has the extension of .aspx.cs. Code behind files contains the code that user writes.
- A web form’s HTML can be edited either in source or design mode. You can also choose SPLIT mode, which shows both the design and the source at the same time.
Design View
Figure 1: Design view of addition of two numbers.
HTML Code
Figure 2: HTML code of web form of addition of two numbers.
C# Code
protected void Button1_Click(object sender, EventArgs e)
{
int Var1 = int.Parse(TextBox1.Text);
int Var2 = int.Parse(TextBox2.Text);
int Var3 = Var1 + Var2;
Label1.Text = "Addition is: " + Var3.ToString();
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
Label1.Text = "";
}
Points to Remember:
- TextBox: It is a control that is used to take text input from user at run time.
- Button: It is a control taht is used to perform some event on its click.
- Label: It is control that is used to display text.
Type of a text property of any control in ASP is string. Therefore to perform addition, we have converted the string value of TextBox1 and TextBox2 into integer and perform arithmetic operation on it and again convert the final result to string and pass it to Label1.
- Datatype.Parse() is a function that takes string as a parameter and convert it in to define data type.
- ToString() is a function that convert any type into string.
Prepared By
Piyush Garg,
Asst. Professor,
Department of CSE, CIST
E-mail: piyushgarg1985@yahoo.com