Practical 2
Practical 2
Practical 2
How to add server controls to your web page. Follow step 1 until step 5 to get the
output as shown in Figure 1.
Textbox
ID : txtName
Button
ID : btnSubmit
Label
ID : lblSelect
Figure 1
1. Create New Project as Practical2. Add a new web form and name it as
servercontrol.aspx.
2. In Design view, drag the highlighted server controls in the red boxes and place it
accordingly as shown in the screen shot below.
TextBox
DropDownList
CheckBoxList
Button
Label
Every server control ID in an asp.net web page must contain a unique identifier. If you do not
assign an ID to a control when you add it in your web page, asp.net will create a default ID
for you.
1. Highlight the server control in the design view and look for ID column in the Properties
window.
2. If you switch your development pane to source view, you can see that the Textbox ID
name under the asp.net tag also changed automatically.
3. Click on the Add button to add 5. Repeat No.3 step to add for another programs.
the list of items. Your DropDownList should have RIS, RSD, RIT, RSF
and REI. Click OK button after you have done adding
all the list.
Follow all the steps to add items as in the DropDownList (Step 3). You will get the same
interface and make sure you add Programming, Database and Networking in the
CheckBoxList items.
You will be directed to ServerControl.aspx.cs code behind page. Copy below code and place
it inside the Button1_Click event.
1. In the same project, go to Solution Explorer window, right click and Click on Add --> New
Item... Choose Master Page and name it as Practical2.Master.
2. Design your Master page to have 4 separated columns as shown below. Use <table>
HTML tag or <div> to design the page.
1. Go to Solution Explorer window, right click and Click on Add --> New Item... Choose
SiteMap and click Add button.
Open the ServerControl.aspx file and make sure you are in the Source view.
2. Type
at the beginning of the page and close the asp content tag at the bottom of the page.
</asp:Content>
Please take note to delete the following tags in the content file:
<!DOCTYPE html>
<form> </form>
<head runat=”server”></head>
<html></html>
<body></body>
*You need to do all these steps if you already have an existing *.aspx page and want to
incorporate it in your master page.
If you switch to the Design view, you will see that the Master page layout has been
embedded in the Content file.
Create a simple Homepage.aspx and include the MasterPageFile. Save and run the
program from this page.
You can navigate the page using the Menu and at the same time, SiteMapPath is showing
on which page you are browsing now.
1. Design a web page for students to apply for a college car sticker and save it as
CarSticker.aspx. Make sure that you use the appropriate asp.net server controls to
obtain the following information.
● Student’s Name
● Student’s ID
● Joined Date
● Gender
● Programmed
● Year of Study
● Vehicle’s Registration Number
● Vehicle’s Type
Display all the selections on a label once the Submit Button is clicked.
Note: You may add other information in the page and use different types of server
controls to gain extra marks.
SiteMapPath
TreeView ContentPlaceHolder
4. Write XML code in Web.SiteMap file to have menu as below. Link all the 3 content files
with the TreeView node.
Homepage
Car Sticker Application
Course Info
The Homepage node in TreeView control will direct the link to the Homepage.aspx content
page, the Car Sticker Application node will direct the link to the CarSticker.aspx content
page and Course Info node will direct the link to the CourseInfo.aspx.