Session 5
Web Server Controls
Exploring ASP.NET / Session 5 / 2 of 29
Review
The @ Page directive is used to specify attributes that affect the
code in the .aspx page.
The <script> section is where most of the code for providing the
required functionality is written.
There are two types of server controls:
HTML Controls
Web Controls
All event procedures receive two arguments from the events:
The event sender
The class instance that holds data for the event
The _VIEWSTATE control is a hidden control that is added to the
form when the form is submitted to the server.
It is possible to check whether a .aspx page is posted back to the
server, with the help of the IsPostBack property of the page.
Exploring ASP.NET / Session 5 / 3 of 29
Review Contd…
ASP.NET has several built-in objects that are used to provide the
required functionality in an ASP.NET application. They are the
following:
Request
Response
Application
Session
Server
ObjectContext
The base directory is called the virtual root, and the directory in which
we store the application files is called the virtual directory.
The Request object corresponds to the request message of the HTTP
protocol, and the Response object corresponds to the response
message of the HTTP protocol.
The Form.Get method of the Request object is used to retrieve the
data submitted by the user.
The Redirect method of the Response object is used to redirect the
user to another page.
Exploring ASP.NET / Session 5 / 4 of 29
Objectives
Explain Web Controls
Explain why controls are objects
Use Controls for Text Entry
Use Controls for Control Transfer
Use Controls for Selection
Discuss Rich Controls
Exploring ASP.NET / Session 5 / 5 of 29
Web Controls
ASP.NET
Controls
Intrinsic
List
Rich
Validation
Exploring ASP.NET / Session 5 / 6 of 29
Web Controls as Objects
Like objects, web controls possess methods and
properties, and respond to events
It is possible to set the properties and call the
methods of the web controls once they are
included onto the web page
Server-side code can be written for the web
control to respond to events that occur on the
client-side
Exploring ASP.NET / Session 5 / 7 of 29
Web Controls as Objects - Example
<html>
<script language="C#" runat ="server" >
void Button1click(Object Src, EventArgs E)
{
lblMessage.Text =Src.ToString();
btnButton1.Enabled = false;
btnButton2.Visible = true;
}
void Button2click(Object Src, EventArgs E)
{
lblMessage.Text="";
btnButton2.Visible = false;
btnButton1.Enabled = true;
}
</script>
Exploring ASP.NET / Session 5 / 8 of 29
Web Controls as Objects - Example
<body>
<form runat="server">
<asp:label id="lblMessage" text="Click on the button"
runat="server"/>
<br><br>
<asp:button id="btnButton1" type = submit text= "Click
me to know who I am" OnClick="Button1click" runat = "server" />
<asp:button id="btnButton2" type = submit text= "Clear
the label" visible=false OnClick="Button2click" runat = "server" />
<br>
</form>
</body>
</html>
Exploring ASP.NET / Session 5 / 9 of 29
Web Controls as Objects - Output
Output of Example 1
Before clicking the button
Output of Example 1
After clicking the button
Exploring ASP.NET / Session 5 / 10 of 29
<input type=
“checkbox”>
<input type= “radio”>
<asp:CheckBox>
<asp:RadioButton>
<asp:TextBox rows=“1”>
<asp:TextBox rows=“10”>
<input type= “text”>
< textarea>
Intrinsic Controls
Exploring ASP.NET / Session 5 / 11 of 29
<asp:textbox id="name"
runat="server"/>
<asp:textbox id="add"
textmode="multiline" rows=“10"
columns="10" runat="server"/>
<asp:textbox id="pwd"
textmode="password" runat="server"/>
Text Entry - Intrinsic Control