Page

Unchecked RadioButton programmatically in asp.net

  1. <%@ Page Language="C#" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <script runat="server">  
  6.     protected void Page_Load(object sender, System.EventArgs e)  
  7.     {  
  8.         if(!this.IsPostBack)  
  9.         {  
  10.             RadioButton1.Checked = true;  
  11.         }  
  12.     }  
  13.     protected void Button1_Click(object sender, System.EventArgs e)  
  14.     {  
  15.         RadioButton1.Checked = false;  
  16.         RadioButton2.Checked = false;  
  17.     }  
  18. </script>  
  19.   
  20. <html xmlns="http://www.w3.org/1999/xhtml">  
  21. <head id="Head1" runat="server">  
  22.     <title>How to unchecked RadioButton programmatically</title>  
  23. </head>  
  24. <body>  
  25.     <form id="form1" runat="server">  
  26.     <div>  
  27.         <h2 style="color:Navy">RadioButton Example: Unchecked</h2>  
  28.         <asp:Label   
  29.              ID="Label1"  
  30.              runat="server"  
  31.              Font-Bold="true"  
  32.              ForeColor="Indigo"  
  33.              Text="Favorite Color?"  
  34.              >  
  35.         </asp:Label>  
  36.         <br />  
  37.         <asp:RadioButton   
  38.              ID="RadioButton1"   
  39.              runat="server"  
  40.              Text="LightBlue"  
  41.              GroupName="Colors"  
  42.              />  
  43.         <asp:RadioButton   
  44.              ID="RadioButton2"   
  45.              runat="server"  
  46.              Text="LightCoral"  
  47.              GroupName="Colors"  
  48.              />  
  49.         <br /><br />             
  50.         <asp:Button   
  51.              ID="Button1"   
  52.              runat="server"   
  53.              ForeColor="Indigo"  
  54.              Text="Unchecked RadioButton"  
  55.              OnClick="Button1_Click"  
  56.              Font-Bold="true"  
  57.              />  
  58.     </div>  
  59.     </form>  
  60. </body>  
  61. </html>  

No comments:

Post a Comment