Next


ASP.NET Server Controls

The ASP.NET Server Controls support server side events. The HTML Client Controls support client side events (java script events).
Server Controls:
1) Core Controls / Standard Controls
2) Data Controls
3) Validation Controls
4) Navigation Controls
5) Login Controls
6) AJAX Extensions
7) Reporting Controls
Note: For every server control, a server side tag will be created in the “Source” view. <asp:ControlName>

i) Core Controls / Standard Controls

a) Button: Performs an operation, whenever it is clicked.

b) Label: Displays a static message

c) TextBox: Used to take input values from the user. TextBox

d) Image: Displays a static image.  Displays a static image

e) Hyperlink: Opens another web page, whenever it is clicked. hyperlink

f) LinkButton: Looks like a hyperlink, and offers button functionality. That means whenever it is clicked, “Click()” event will be executed. linkbuttion

g) ImageButton: Looks like a image control, but offers button functionality. It executes “Click()” event, whenever it is clicked. ImageButton

h) CheckBox: Offers to check / un-check the checkbox. CheckBox

i) RadioButton: At least 2 or more radio buttons are to be placed. The user can select any one of the radio buttons. RadioButton

j) CheckBoxList: Contains multiple check boxes as items RadioButton

k) RadioButtonList: Contains multiple radio buttons as items. It offers automatic grouping nature of all the radio buttons, without specifying the “GroupName” property. RadioButton

l) ListBox: Displays multiple items as options, so that the user can select any one (or more) items. ListBox

m) DropDownList: Displays multiple items as options, so that the user can select any one of the items. It is same as “Combo box” in windows applications. DropDownList

n) Table: It is an imitation to html tables. It offers to create tables with few rows and columns, without typing the table tags. Table

o) Literal: Displays the output of html tags. It supports all the html tags. Literal

p) Calendar: Displays a calendar. The user can switch to previous / next month. Calendar

q) Panel: Acts as container for other controls. Panel

Demo on Standard Controls Demo on Standard Controls

Design




Button1
    Text: Click Me
Label1
TextBox1
    AutoPostBack: true
Image1
    ImageUrl: c:\globe.jpg
Hyperlink1
    Text: Click here to open Default2 Page
    NavigateUrl: Default2.aspx
Hyperlink2
    ImageUrl: c:\globe2.jpg
    NavigateUrl: Default2.aspx
LinkButton1
    Text: My Link Button
ImageButton1
    ImageUrl: c:\globe2.jpg
CheckBox1
    Text: My Check Box
RadioButton1
    Text: My Radio Button 1
    GroupName: g1
    AutoPostBack: true
RadioButton2
    Text: My Radio Button 2
    GroupName: g1
    AutoPostBack: true
CheckBoxList1
    Items: First CheckBox, Second CheckBox, Third CheckBox
    AutoPostBack: true
RadioButtonList1
    Items: First RadioButton, Second RadioButton, Third RadioButton
    AutoPostBack: true
ListBox1
    Items: First ListBox Option, Second ListBox Option, Third ListBox Option
    AutoPostBack: true
ListBox2
    Items: First ListBox Option, Second ListBox Option, Third ListBox Option, Fourth ListBox Option
    AutoPostBack: true
    SelectionMode: Multiple
DropDownList1
    Items: First DropDown Option, Second DropDown Option, Third DropDown Option, Fourth DropDown Option
    AutoPostBack: true
Table1
    Rows: Add three rows as shown in the above screen
    Caption: Employees
    GridLines: Both
Literal1
    Text: <marquee bgcolor=pink><h1>This is literal control</h1></marquee>
Calendar1
Panel1
    BackColor: LightYellow


    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text = "Welcome to the page.";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "The button is clicked.";
    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Label1.Text = TextBox1.Text;
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Label1.Text = "The link button is clicked.";
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Label1.Text = "The image button is clicked.";
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (CheckBox1.Checked)
            Label1.Text = "The check box is checked.";
        else
            Label1.Text = "The check box is un-checked.";
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        Label1.Text = "My Radio Button 1 is selected.";
    }
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        Label1.Text = "My Radio Button 2 is selected.";
    }
    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "";
        int count = 0;
        for (int i = 0; i < CheckBoxList1.Items.Count; i++)
        {
            if (CheckBoxList1.Items[i].Selected)
            {
                Label1.Text = Label1.Text + CheckBoxList1.Items[i].Text + ", ";
                count++;
            }
        }
        if (count > 0)
            Label1.Text = Label1.Text + " are selected.";
        else
            Label1.Text = "No CheckboxList items are selected.";
    }

    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = RadioButtonList1.SelectedItem.Text + " is selected.";
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = ListBox1.SelectedItem.Text + " is selected.";
    }
    protected void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "";
        int count = 0;
        for (int i = 0; i < ListBox2.Items.Count; i++)
        {
            if (ListBox2.Items[i].Selected)
            {
                Label1.Text = Label1.Text + ListBox2.Items[i].Text + ", ";
                count++;
            }
        }
        if (count > 0)
            Label1.Text = Label1.Text + " are selected.";
        else
            Label1.Text = "No ListBox items are selected.";
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = DropDownList1.SelectedItem.Text + " is selected.";
    }
    protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        Label1.Text = Calendar1.SelectedDate.ToShortDateString()+ " is selected in the calendar.";        
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Label1.Text = "Search string is: " + TextBox2.Text;
    }



Syntax for Absolute Positioning: <tag runat=”server” Style=”position:absolute; left:xxxx; top:xxxx” />