In this article we will introduce with HTML CheckBox control in ASP.NET using C#.
HTML CheckBox Example in ASP.NET Using C#
HTML Checkbox be a Part of HTML Control in Asp.net Toolbox. Checkbox let user selected multiple choice of option. for input choice checkbox object is created and using tag : <input type="checkbox">. Syntax: <input type="checkbox" id="Chkindia" />.

Checkbox2.aspx(Source code):
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="checkbox2.aspx.cs" Inherits="checkbox2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>How to use HTML Input Checkbox</title> <script language="javascript" type="text/javascript"> </script> </head> <body> <form id="HTMLInputCheckBox" method="post" runat="server"> <p> <strong>Please choose a Country that like.</strong></p> <input id="Chkindia" type="checkbox" runat="server" /> INDIA<br /> <input id="ChkBHARAT" type="checkbox" runat="server" /> BHARAT<p> <input id="btnSubmit" runat="server" type="submit" onserverclick="btnSubmit_Click" value="Submit" onclick="return btnSubmit_onclick()" /> </p> </form> <div id="lbltext" runat="server"> </div> </body> </html>
Checkbox2.aspc.cs (C# Code file)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class checkbox2 : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, System.EventArgs e)
{
string strResponse = "";
if (Chkindia.Checked)
{
strResponse += "INDIA ";
}
if (ChkBHARAT.Checked)
{
strResponse += "BHARAT";
}
if (Page.IsPostBack)
{
lbltext.InnerHtml = "Select Option: " + strResponse;
}
}
}
Output Display:


[ 0 ] Comments