1) Copy this code in Sample.aspx Page under the form Tag.
<div>
<table cellpadding="10">
<tr>
<td>
Control Name
</td>
<td>
Control
</td>
<td>
Get Value
</td>
<td>
<asp:Label ID="lblTitle" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
TextBox
</td>
<td>
<asp:TextBox ID="txtSampleTextbox" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnTextbox" runat="server" Text="Get Value" OnClick="btnTextbox_Click" />
</td>
<td>
<asp:Label ID="lblTextBox" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
Radio Button List
</td>
<td>
<asp:RadioButtonList ID="rblSampleRadioButtonList" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Button ID="btnRadioButtonList" runat="server" Text="Get Value" OnClick="btnRadioButtonList_Click" />
</td>
<td>
<asp:Label ID="lblRadioButtonList" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
ListBox
</td>
<td>
<asp:ListBox ID="lstSampleListBox" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button ID="btnListBox" runat="server" Text="Get Value" OnClick="btnListBox_Click" />
</td>
<td>
<asp:Label ID="lblListBox" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
Link Button
</td>
<td>
<asp:LinkButton ID="lnkSampleLinkButton" runat="server" PostBackUrl="http://www.yahoo.com">Click here to Redirect Yahoo!</asp:LinkButton>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Image Button
</td>
<td>
<asp:ImageButton ID="ImgbtnSampleImageButton" runat="server" ImageUrl="~/Images/btnClick.png"
OnClick="ImgbtnSampleImageButton_Click" />
</td>
<td>
Click On Image
</td>
<td>
<asp:Label ID="lblImageButton" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
DropDownList
</td>
<td>
<asp:DropDownList ID="ddlSampleDropDownList1" runat="server" OnSelectedIndexChanged="ddlSampleDropDownList1_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem>Option 1</asp:ListItem>
<asp:ListItem>Option 2</asp:ListItem>
<asp:ListItem>Option 3</asp:ListItem>
<asp:ListItem>Option 4</asp:ListItem>
</asp:DropDownList>
</td>
<td>
Select Option from DropDownList
</td>
<td>
<asp:Label ID="lblDropDownList" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
CheckBoxList
</td>
<td>
<asp:CheckBoxList ID="cblSampleCheckBoxList" runat="server" OnSelectedIndexChanged="cblSampleCheckBoxList_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem>Select 1</asp:ListItem>
<asp:ListItem>Select 2</asp:ListItem>
<asp:ListItem>Select 3</asp:ListItem>
<asp:ListItem>Select 4</asp:ListItem>
</asp:CheckBoxList>
</td>
<td>
Select Checkbox Value from the List
</td>
<td>
<asp:Label ID="lblCheckBoxList" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
Calender
</td>
<td>
<table>
<tr>
<td>
<asp:Calendar ID="calSampleCalendar" runat="server" OnSelectionChanged="calSampleCalendar_SelectionChanged">
</asp:Calendar>
</td>
<td>
<asp:TextBox ID="txtCalender" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</td>
<td>
Select Date From Calender
</td>
<td>
<asp:Label ID="lblCalender" runat="server" Text="Value"></asp:Label>
</td>
</tr>
</table>
protected void btnTextbox_Click(object sender, EventArgs e)
{
lblTextBox.Text = txtSampleTextbox.Text;
}
protected void btnRadioButtonList_Click(object sender, EventArgs e)
{
lblRadioButtonList.Text = rblSampleRadioButtonList.SelectedItem.Text;
}
protected void btnListBox_Click(object sender, EventArgs e)
{
lblListBox.Text = lstSampleListBox.SelectedItem.Text;
}
protected void ImgbtnSampleImageButton_Click(object sender, ImageClickEventArgs e)
{
lblImageButton.Text = "You clicked Button";
}
protected void ddlSampleDropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lblDropDownList.Text = ddlSampleDropDownList1.SelectedItem.Text;
}
protected void cblSampleCheckBoxList_SelectedIndexChanged(object sender, EventArgs e)
{
lblCheckBoxList.Text = cblSampleCheckBoxList.SelectedItem.Text;
}
protected void calSampleCalendar_SelectionChanged(object sender, EventArgs e)
{
lblCalender.Text = calSampleCalendar.SelectedDate.ToString();
txtCalender.Text = calSampleCalendar.SelectedDate.ToString();
}
btn - Button
cb - CheckBox
cbl - CheckBoxList
ddl - DropDownList
dtv - DetailsView
fmv - FormView
grdv - GridView
hl - Hyperlink
img - Image
ib - ImageButton
lbl - Label
lbtn - LinkButton
lb - ListBox
lit - Literal
mnu - Menu
pnl - Panel
ph - PlaceHolder
rb - RadioButton
rbl - RadioButtonList
rpt - Repeater
sql - SqlDataSource
txt - Textbox
<div>
<table cellpadding="10">
<tr>
<td>
Control Name
</td>
<td>
Control
</td>
<td>
Get Value
</td>
<td>
<asp:Label ID="lblTitle" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
TextBox
</td>
<td>
<asp:TextBox ID="txtSampleTextbox" runat="server"></asp:TextBox>
</td>
<td>
<asp:Button ID="btnTextbox" runat="server" Text="Get Value" OnClick="btnTextbox_Click" />
</td>
<td>
<asp:Label ID="lblTextBox" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
Radio Button List
</td>
<td>
<asp:RadioButtonList ID="rblSampleRadioButtonList" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:Button ID="btnRadioButtonList" runat="server" Text="Get Value" OnClick="btnRadioButtonList_Click" />
</td>
<td>
<asp:Label ID="lblRadioButtonList" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
ListBox
</td>
<td>
<asp:ListBox ID="lstSampleListBox" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
</asp:ListBox>
</td>
<td>
<asp:Button ID="btnListBox" runat="server" Text="Get Value" OnClick="btnListBox_Click" />
</td>
<td>
<asp:Label ID="lblListBox" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
Link Button
</td>
<td>
<asp:LinkButton ID="lnkSampleLinkButton" runat="server" PostBackUrl="http://www.yahoo.com">Click here to Redirect Yahoo!</asp:LinkButton>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
Image Button
</td>
<td>
<asp:ImageButton ID="ImgbtnSampleImageButton" runat="server" ImageUrl="~/Images/btnClick.png"
OnClick="ImgbtnSampleImageButton_Click" />
</td>
<td>
Click On Image
</td>
<td>
<asp:Label ID="lblImageButton" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
DropDownList
</td>
<td>
<asp:DropDownList ID="ddlSampleDropDownList1" runat="server" OnSelectedIndexChanged="ddlSampleDropDownList1_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem>Option 1</asp:ListItem>
<asp:ListItem>Option 2</asp:ListItem>
<asp:ListItem>Option 3</asp:ListItem>
<asp:ListItem>Option 4</asp:ListItem>
</asp:DropDownList>
</td>
<td>
Select Option from DropDownList
</td>
<td>
<asp:Label ID="lblDropDownList" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
CheckBoxList
</td>
<td>
<asp:CheckBoxList ID="cblSampleCheckBoxList" runat="server" OnSelectedIndexChanged="cblSampleCheckBoxList_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem>Select 1</asp:ListItem>
<asp:ListItem>Select 2</asp:ListItem>
<asp:ListItem>Select 3</asp:ListItem>
<asp:ListItem>Select 4</asp:ListItem>
</asp:CheckBoxList>
</td>
<td>
Select Checkbox Value from the List
</td>
<td>
<asp:Label ID="lblCheckBoxList" runat="server" Text="Value"></asp:Label>
</td>
</tr>
<tr>
<td>
Calender
</td>
<td>
<table>
<tr>
<td>
<asp:Calendar ID="calSampleCalendar" runat="server" OnSelectionChanged="calSampleCalendar_SelectionChanged">
</asp:Calendar>
</td>
<td>
<asp:TextBox ID="txtCalender" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</td>
<td>
Select Date From Calender
</td>
<td>
<asp:Label ID="lblCalender" runat="server" Text="Value"></asp:Label>
</td>
</tr>
</table>
</div>
2) Copy this code in Sample.aspx.cs page below pageload method complate.
{
lblTextBox.Text = txtSampleTextbox.Text;
}
protected void btnRadioButtonList_Click(object sender, EventArgs e)
{
lblRadioButtonList.Text = rblSampleRadioButtonList.SelectedItem.Text;
}
protected void btnListBox_Click(object sender, EventArgs e)
{
lblListBox.Text = lstSampleListBox.SelectedItem.Text;
}
protected void ImgbtnSampleImageButton_Click(object sender, ImageClickEventArgs e)
{
lblImageButton.Text = "You clicked Button";
}
protected void ddlSampleDropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
lblDropDownList.Text = ddlSampleDropDownList1.SelectedItem.Text;
}
protected void cblSampleCheckBoxList_SelectedIndexChanged(object sender, EventArgs e)
{
lblCheckBoxList.Text = cblSampleCheckBoxList.SelectedItem.Text;
}
protected void calSampleCalendar_SelectionChanged(object sender, EventArgs e)
{
lblCalender.Text = calSampleCalendar.SelectedDate.ToString();
txtCalender.Text = calSampleCalendar.SelectedDate.ToString();
}
above code is the simplest way to get the value from the control please write comment if you want specif way or specific data to get with some condition.
below is some more Naming convention.
cb - CheckBox
cbl - CheckBoxList
ddl - DropDownList
dtv - DetailsView
fmv - FormView
grdv - GridView
hl - Hyperlink
img - Image
ib - ImageButton
lbl - Label
lbtn - LinkButton
lb - ListBox
lit - Literal
mnu - Menu
pnl - Panel
ph - PlaceHolder
rb - RadioButton
rbl - RadioButtonList
rpt - Repeater
sql - SqlDataSource
txt - Textbox