ASP.Net/Asp Control/CheckBox

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

asp:CheckBox: change font and border (VB.net)

   <source lang="csharp">

<%@ 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) & "<" & "/" & "SCRIPT>")
   End If
   If chkContact.Checked = "True" Then 
       Response.Write ("<SCRIPT LANGUAGE=""JavaScript"">" _
           & Chr(13) & "<" & "/" & "SCRIPT>")
   End If    

End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Displaying a Basic CheckBox Control</TITLE> </HEAD> <form runat="server">

<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" 

/>

<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" 

/>

<asp:button

   id="butOK"
   text="OK"
   Type="Submit"
   OnClick="SubmitBtn_Click" 
   runat="server"

/> </form> </BODY> </HTML>

      </source>
   
  


asp:CheckBox: text align (VB.net)

   <source lang="csharp">

<%@ 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) & "<" & "/" & "SCRIPT>")
   End If
   If chkContact.Checked = "True" Then 
       Response.Write ("<SCRIPT LANGUAGE=""JavaScript"">" _
           & Chr(13) & "<" & "/" & "SCRIPT>")
   End If    

End Sub </SCRIPT> <HTML> <HEAD> <TITLE>Displaying a Basic CheckBox Control</TITLE> </HEAD> <form runat="server">

<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" 

/>

<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" 

/>

<asp:button

   id="butOK"
   text="OK"
   Type="Submit"
   OnClick="SubmitBtn_Click" 
   runat="server"

/> </form> </BODY> </HTML>

      </source>
   
  


CheckBox AutoPostBack (VB.net)

   <source lang="csharp">

<%@ 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">
   <asp:CheckBox
       id="chkNewsletter"
       Text="Receive Newsletter?"
       AutoPostBack="true"
       OnCheckedChanged="chkNewsletter_CheckedChanged" 
       Runat="server" />

   <asp:Label
       id="lblResult"
       Runat="server" />
   
   </form>

</body> </html>

</source>
   
  


Get Check box selection state (C#)

   <source lang="csharp">

<%@ 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">
   <asp:CheckBox
       id="chkNewsletter"
       Text="Receive Newsletter?"
       Runat="server" />
   
<asp:Button id="btnSubmit" Text="Submit" OnClick="btnSubmit_Click" Runat="server" />

   <asp:Label
       id="lblResult"
       Runat="server" />
   
   </form>

</body> </html>

      </source>
   
  


On asp:CheckBox selection state changed (VB.net)

   <source lang="csharp">

<%@ 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">

<asp:checkbox

   id="chk"
   text="Would you like to go to nfex.ru?"
   autopostback="true"
   oncheckedchanged="chk_Clicked"
   runat="server" 

/> </form> </BODY> </HTML>

      </source>
   
  


On checkbox changed event (C#)

   <source lang="csharp">

<%@Page Language="C#" %> <html> <head> <title>Web Form "Change" and "Click" Events</title> </head> <body> Web Form "Change" and "Click" Events<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 />

Change the values in the controls and click "Submit"

<script runat="server"> void MyChangeCode(object objSender, EventArgs objArgs) {

 Control ctrSender = (Control)objSender;
 divResult.InnerHtml += "Change event detected for control ""
                     + ctrSender.ID + ""
";

} void MyClickCode(object objSender, EventArgs objArgs) {

 Control ctrSender = (Control)objSender;
 divResult.InnerHtml += "Click event detected for control ""
                     + ctrSender.ID + ""
";

} </script> </body> </html>

      </source>
   
  


Set asp:checkbox checked (VB.net)

   <source lang="csharp">

<%@ 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>

Selection Control Example

  <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>

      </source>
   
  


Set Text, TextAlign and Font name for a asp:CheckBox (C#)

   <source lang="csharp">

<%@ 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">

<asp:CheckBox

   id="chk1"
   Text="Do you like the color blue?" 
   TextAlign="Left"
   Font-Size="12pt"
   Font-Name="Comic Sans MS"
   runat="server" 

/>

<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" 

/> </Form> </BODY> </HTML>

      </source>
   
  


Set Text, TextAlign and Font name for a asp:CheckBox (VB.net)

   <source lang="csharp">

<%@ 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">

<asp:CheckBox

   id="chk1"
   Text="Do you like the color blue?" 
   TextAlign="Left"
   Font-Size="12pt"
   Font-Name="Comic Sans MS"
   runat="server" 

/>

<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" 

/> </Form> </BODY> </HTML>

      </source>