ASP.Net/Asp Control/CheckBox
Содержание
- 1 asp:CheckBox: change font and border (VB.net)
- 2 asp:CheckBox: text align (VB.net)
- 3 CheckBox AutoPostBack (VB.net)
- 4 Get Check box selection state (C#)
- 5 On asp:CheckBox selection state changed (VB.net)
- 6 On checkbox changed event (C#)
- 7 Set asp:checkbox checked (VB.net)
- 8 Set Text, TextAlign and Font name for a asp:CheckBox (C#)
- 9 Set Text, TextAlign and Font name for a asp:CheckBox (VB.net)
asp:CheckBox: change font and border (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
If chkMailingList.Checked = "True" Then
Response.Write ("<SCRIPT LANGUAGE=""JavaScript"">" _
& Chr(13) & "<!--" & Chr(13) _
& "alert("You have been added to " _
& "our mailing list")" & Chr(13) _
& "--><" & "/" & "SCRIPT>")
End If
If chkContact.Checked = "True" Then
Response.Write ("<SCRIPT LANGUAGE=""JavaScript"">" _
& Chr(13) & "<!--" & Chr(13) _
& "alert("We will contact you " _
& "by phone")" & Chr(13) _
& "--><" & "/" & "SCRIPT>")
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Displaying a Basic CheckBox Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
<asp:checkbox
id="chkMailingList"
text="Would you like to be on our mailing list?"
checked="true"
backcolor="LightYellow"
bordercolor="DarkRed"
borderwidth=3
font-size="12pt"
font-name="Comic Sans MS"
textalign="Left"
runat="server"
/>
<BR><BR>
<asp:checkbox
id="chkContact"
text="Would you like us to contact you by phone?"
checked="false"
backcolor="LightYellow"
bordercolor="DarkRed"
borderwidth=3
font-size="12pt"
font-name="Comic Sans MS"
textalign="Right"
runat="server"
/>
<BR><BR>
<asp:button
id="butOK"
text="OK"
Type="Submit"
OnClick="SubmitBtn_Click"
runat="server"
/>
</form>
</BODY>
</HTML>
asp:CheckBox: text align (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
If chkMailingList.Checked = "True" Then
Response.Write ("<SCRIPT LANGUAGE=""JavaScript"">" _
& Chr(13) & "<!--" & Chr(13) _
& "alert("You have been added to " _
& "our mailing list")" & Chr(13) _
& "--><" & "/" & "SCRIPT>")
End If
If chkContact.Checked = "True" Then
Response.Write ("<SCRIPT LANGUAGE=""JavaScript"">" _
& Chr(13) & "<!--" & Chr(13) _
& "alert("We will contact you " _
& "by phone")" & Chr(13) _
& "--><" & "/" & "SCRIPT>")
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Displaying a Basic CheckBox Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
<asp:checkbox
id="chkMailingList"
text="Would you like to be on our mailing list?"
checked="true"
backcolor="LightYellow"
bordercolor="DarkRed"
borderwidth=3
font-size="12pt"
font-name="Comic Sans MS"
textalign="Left"
runat="server"
/>
<BR><BR>
<asp:checkbox
id="chkContact"
text="Would you like us to contact you by phone?"
checked="false"
backcolor="LightYellow"
bordercolor="DarkRed"
borderwidth=3
font-size="12pt"
font-name="Comic Sans MS"
textalign="Right"
runat="server"
/>
<BR><BR>
<asp:button
id="butOK"
text="OK"
Type="Submit"
OnClick="SubmitBtn_Click"
runat="server"
/>
</form>
</BODY>
</HTML>
CheckBox AutoPostBack (VB.net)
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub chkNewsletter_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
lblResult.Text = chkNewsletter.Checked.ToString()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>CheckBox AutoPostBack</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox
id="chkNewsletter"
Text="Receive Newsletter?"
AutoPostBack="true"
OnCheckedChanged="chkNewsletter_CheckedChanged"
Runat="server" />
<hr />
<asp:Label
id="lblResult"
Runat="server" />
</div>
</form>
</body>
</html>
Get Check box selection state (C#)
<%@ Page Language="C#" %>
<script runat="server">
protected void btnSubmit_Click(object sender, EventArgs e)
{
lblResult.Text = chkNewsletter.Checked.ToString();
}
</script>
<html>
<head>
<title>Show CheckBox</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBox
id="chkNewsletter"
Text="Receive Newsletter?"
Runat="server" />
<br />
<asp:Button
id="btnSubmit"
Text="Submit"
OnClick="btnSubmit_Click"
Runat="server" />
<hr />
<asp:Label
id="lblResult"
Runat="server" />
</div>
</form>
</body>
</html>
On asp:CheckBox selection state changed (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub chk_Clicked(Sender As Object, E As EventArgs)
if chk.Checked = True Then
Response.Redirect("http://www.nfex.ru")
End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Displaying a Basic CheckBox Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
<asp:checkbox
id="chk"
text="Would you like to go to nfex.ru?"
autopostback="true"
oncheckedchanged="chk_Clicked"
runat="server"
/>
</form>
</BODY>
</HTML>
On checkbox changed event (C#)
<%@Page Language="C#" %>
<html>
<head>
<title>Web Form "Change" and "Click" Events</title>
</head>
<body>
<span class="heading">Web Form "Change" and "Click" Events</span><p />
<form runat="server">
<asp:textbox id="MyText" text="OriginalValue"
ontextchanged="MyChangeCode" runat="server" />
<asp:dropdownlist id="MyListBox"
onselectedindexchanged="MyChangeCode" runat="server">
<asp:listitem text="Option 1" value="Value1" runat="server" />
<asp:listitem text="Option 2" value="Value2" runat="server" />
<asp:listitem text="Option 3" value="Value3" runat="server" />
</asp:dropdownlist>
<asp:checkbox id="MyCheckBox"
oncheckedchanged="MyChangeCode" runat="server" />
<asp:button id="MySubmitButton" text="Submit"
onclick="MyClickCode" runat="server" />
</form>
<div id="divResult" runat="server" enableviewstate="false" /><p />
<div class="cite">Change the values in the controls and click "Submit"</div>
<script runat="server">
void MyChangeCode(object objSender, EventArgs objArgs) {
Control ctrSender = (Control)objSender;
divResult.InnerHtml += "Change event detected for control ""
+ ctrSender.ID + ""<br />";
}
void MyClickCode(object objSender, EventArgs objArgs) {
Control ctrSender = (Control)objSender;
divResult.InnerHtml += "Click event detected for control ""
+ ctrSender.ID + ""<br />";
}
</script>
</body>
</html>
Set asp:checkbox checked (VB.net)
<%@ Page Language="vb" %>
<html>
<head>
<title>Selection Control Example</title>
<script runat="server">
Sub Page_Load()
MyCheckBox1.Checked = True
MyRadioButton1.Checked = False
MyListBox.SelectionMode = ListSelectionMode.Multiple
MyDropDownList.SelectedIndex = 1
MyCheckBoxList.RepeatDirection = RepeatDirection.Horizontal
MyRadioButtonList.RepeatLayout = RepeatLayout.Table
End Sub
</script>
</head>
<body>
<h1>Selection Control Example</h1>
<form runat="server">
<asp:table id="MyTable" border="1" cellpadding="5" cellspacing="0" runat="server">
<asp:tablerow runat="server">
<asp:tablecell runat="server">
CheckBox Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:checkbox id="MyCheckBox1"
text="Vanilla" runat="server" />
<asp:checkbox id="MyCheckBox2"
text="Chocolate" runat="server" />
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
RadioButton Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:radiobutton id="MyRadioButton1" groupname="Group1"
checked=True text="Yes" runat="Server"/>
<asp:radiobutton id="MyRadioButton2" groupname="Group1"
text="No" runat="Server"/>
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
ListBox Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:listbox id="MyListBox" runat="server">
<asp:listitem value="Vanilla" selected="true">Vanilla</asp:listitem>
<asp:listitem value="Chocolate">Chocolate</asp:listitem>
<asp:listitem value="Strawberry">Strawberry</asp:listitem>
</asp:listbox>
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
DropDownList Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:dropdownlist id="MyDropDownList" runat="server">
<asp:listitem value="Single" selected="true">Single</asp:listitem>
<asp:listitem value="Multiline">Multiline</asp:listitem>
<asp:listitem value="Password">Password</asp:listitem>
</asp:dropdownlist>
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
CheckBoxList Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:checkboxlist id="MyCheckBoxList"
repeatdirection="vertical" runat="server">
<asp:listitem value="Vanilla" text="Vanilla"/>
<asp:listitem value="Chocolate" text="Chocolate"/>
<asp:listitem value="Strawberry" text="Strawberry"/>
</asp:checkboxlist>
</asp:tablecell>
</asp:tablerow>
<asp:tablerow runat="server">
<asp:tablecell runat="server">
RadioButtonList Control:
</asp:tablecell>
<asp:tablecell runat="server">
<asp:radiobuttonlist id="MyRadioButtonList" repeatdirection="Horizontal" runat="server">
<asp:listitem value="Female" text="Female" selected="true"/>
<asp:listitem value="Male" text="Male"/>
</asp:radiobuttonlist>
</asp:tablecell>
</asp:tablerow>
</asp:table>
</form>
</body>
</html>
Set Text, TextAlign and Font name for a asp:CheckBox (C#)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>CheckBox Controls Sample Page</TITLE>
</HEAD>
<BODY>
<form runat="server">
<Font Face="Tahoma" Size="+1">
<BR><BR>
<asp:CheckBox
id="chk1"
Text="Do you like the color blue?"
TextAlign="Left"
Font-Size="12pt"
Font-Name="Comic Sans MS"
runat="server"
/>
<BR><BR>
<asp:CheckBox
id="chk2"
Checked="True"
Text="Do you like the color red?"
TextAlign="Right"
Font-Size="12pt"
Font-Name="Comic Sans MS"
runat="server"
/>
</Font>
</Form>
</BODY>
</HTML>
Set Text, TextAlign and Font name for a asp:CheckBox (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>CheckBox Controls Sample Page</TITLE>
</HEAD>
<BODY>
<form runat="server">
<Font Face="Tahoma" Size="+1">
<BR><BR>
<asp:CheckBox
id="chk1"
Text="Do you like the color blue?"
TextAlign="Left"
Font-Size="12pt"
Font-Name="Comic Sans MS"
runat="server"
/>
<BR><BR>
<asp:CheckBox
id="chk2"
Checked="True"
Text="Do you like the color red?"
TextAlign="Right"
Font-Size="12pt"
Font-Name="Comic Sans MS"
runat="server"
/>
</Font>
</Form>
</BODY>
</HTML>