Nit L 3
Nit L 3
ASP.NET
By: Dr. Galal AL-Marzoqi
1
Lecture 3
are web pages built on ASP.NET technology. It is executed on the server and
development environment (IDE) that allows us to drag and drop server controls
1. Properties,
2. Events,
Web Forms represented by .aspx files are the central of any ASP.NET Web Forms
programming logic).
2
➢ The Different Views on Web Forms
In this section, see three buttons that enables you to look at your Web Form from different
views. in Figure below, we can see three buttons so important:
1. Design button: The Design button enables you to switch the Document Window into Design
View, which gives you an idea of how the page will end up.
2. The Split button: Split View is great if you want to see the code that VS generates when you
add controls to the Design View of your page.
3. Source button: View is the default view when you open a page. It shows you the raw HTML
and other markup for the page, and is very useful if you want to tweak the contents of a page ( it
is can see all code).
3
Server Controls
Server Control is a tag written in a Web page to represent a programmable server-
side object used for displaying a user interface element in a Web page.
ASP.NET server controls are tags that can be understood by the server.
➢ TYPES OF CONTROLS
4
➢ Standard Controls (Simple and List Controls)
It easy for you to find the right controls, they have been placed in separate
control categories in the VS Toolbox (accessible by pressing Ctrl+Alt+X).
1. Simple Controls:
The simple controls represent some controls such as (TextBox, Button, Label,
HyperLink, RadioButton, and CheckBox) that found in standard control inside
Toolbox.
We can descript some controls. The table represents some simple controls that found in
Standard Controls
Control Name Suitable Events Description
TextBox TextChanged It is used to create a text input in the form.
Button Click, Command It is used to create a button.
Label None It is used to display text on the HTML page.
HyperLink None It is used to create a hyperlink control that responds to a click
event.
RadioButton CheckChanged It is used to create radio button.
CheckBox CheckChanged It is used to create checkbox.
5
✓ TextBox
This is an input control which is used to take user input. To create TextBox either
we can write code or use the drag and drop ability of visual studio IDE.
The example is given below
✓ This is server-side control, asp provides own tag to create it.
< asp:TextBoxID="TextBox1" runat="server" ></asp:TextBox>
- The ID is important that each control on the page has a unique ID.
- The runat attribute is used to indicate to control that lives on the server.
✓ Server renders it as the HTML control and produces the following code to the browser.
<input name="TextBox1" id="TextBox1" type="text">
property Description
Note: The TextBox contains an important property called TextMode. By using this property
you can set textbox as:
• SingleLine mode: is default mode of textbox control to enter data in a single line.
• MultiLine mode: enables user to enter text in more than one line.
• Password mode: text is hidden the values entered by the user.
6
✓ Button
It is used to submit client request to the server or a command button. To
create Button either we can write code or use the drag and drop facility of visual
studio IDE.
• Button
• Link Button
• Image Button
✓ This is a server-side control and asp provides own tag to create it.
< asp:ButtonID="Button1" runat="server" Text="Submit" BorderStyle="Solid" Tool
Tip="Submit"/>
✓ Server renders it as the HTML control and produces the following code to the
browser.
➢ This control has its own properties that are tabled below.
Property Description
7
C# Code:
1. using System;
2. using System.Collections.Generic;
3. using System.Linq;
4. using System.Web;
5. using System.Web.UI;
6. using System.Web.UI.WebControls;
7. namespace WebFormsControlls
8. {
10. {
12. {
14. } } }
Output:
8
✓ HyperLink
It is a control used to create a hyperlink and responds to a click event. We can use
it to refer any web page on the server. To create HyperLink either we can write
code or use the drag and drop ability of visual studio IDE. This control is listed in
the toolbox.
✓ Server renders it as the HTML control and produces the following code to the
browser.
➢ This control has its own properties that are tabled below.
Property Description
9
This property window shows properties for the HyperLink control.
Output:
10
2. List Controls:
✓ DropDownList
The DropDownList is a web server control that used to create an HTML Select
element. It allows to select an option from the dropdown list. It can contain any
number of items.
✓ There are two ways for create DropDownList in asp.net:
<asp:ListItem>Yemen</asp:ListItem>
<asp:ListItem>NewYork</asp:ListItem>
</asp:DropDownList>
11
➢ The second way: We can create DropDownList by use the drag and drop
ability of visual studio.
Click on the items (collection) and it will pop up a new window as given below. It provides add
button to add new items to the list, see figure 3 and 4
Adding item to the DropDownList, by providing values to the Text and Value properties. We
have added more items to it and now, it looks like the following in figure 5 and 6.
12
After that, we create button control by C# for using DropDownlist.
Code C#:
protected void Button1_Click(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "") {
Label1.Text = "Please Select a City";
else }
Label1.Text = "Your Choice is: " + DropDownList1.SelectedValue; }
13