.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

The dreaded Checkbox Empty Validation problem

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :ASP.Net

I've seen zillions of postings on how to deal with the issue where you need to validate a Checkbox to ensure the user has checked it "true" or "on", or "checked".  Useful for making them confirm they have read and/or agree to something.

It seems unfortunate that the base controls don't handle this, and many others agree with me...nonetheless...

I have tried to implement a hybrid of some of these solutions.  Anyway, here's what I've put together, and I am not skilled enough to know why this does not work.  It doesn't generate any errors, and when I look at the rendered HTML via "view page source", there is nothing obvious that I see...for example, all the controls appear to be there and seem to render the same as any of the static HTML controls that are also on the page.

Anyone able to enlighten me?  Thanks in advance:

1.  In a utility library, I create a class that inherits from the CheckBox class, so that I can dynamically create it in code.  (I don't want to bother creating a UserControl for this because it seems like overkill to implement a single missing (my opinion) property.  I lifed the equivalent of this code from other forum posts.

namespace CommonClasses
    //extend the standar

View Complete Post

More Related Resource Links

Checkbox Value Problem


Hi Guys,

I have a problem with razor in a checkbox. It does not get a checked value.

Here is the code:

PageData["Title"] = "Edit Your Profile - ";

var db = Database.OpenFile("mySite.sdf");
var selectQuerySingle = "SELECT * FROM UserProfiles, webpages_Membership WHERE UserProfiles.UserId = webpages_Membership.UserId AND UserProfiles.UserId=@0 AND webpages_Membership.UserId=@0 ";
var UserId = UrlData[0];

if (UserId.IsEmpty())

var row = db.QuerySingle(selectQuerySingle, UserId);

var firstname = row.firstname;
var lastname = row.lastname;
var email = row.email;
var phone = row.phone;
var address = row.address;
var city = row.city;
var zipcode = row.zipcode;
var country = row.country;
var isconfirmed = "";

if (IsPost)

firstname = Request["firstname

validation problem

hii design a register users form for my wesite.i using validation controls in my form, for instance(requiredfield validator and compare validator)i make validation group for my validation controls and register buttonvalidation group is equal for all my validation controls and button. when is empty one of textboxes and i click on register button first run button function then enable validationsthis is my problemthe validations must enable before run the button functionthis is my html codes:<table class="format">                                <tr>                                    <td colspan="2">                                        <asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Names="Tahoma"             &n

Date validation problem modelstate.isvalid is false

In my view i am formatting the date as follows<%= Html.TextBox("MemoDate", string.Format("{0:dd/MM/yyyy hh:mm}", DateTime.Now),new{ @readonly = true })%> In controller ModelState.IsValid become false as my current culture culture {en-US} doesn't match with the format of date.

SSRS 2008 R2 Problem understanding View State Validation steps

Hi, Sorry, but I have some problem understanding this steps. Please help me to understand this.  Pasted from http://technet.microsoft.com/en-us/library/cc281307.aspx?lc=1033 How to Configure View State Validation To run a scale-out deployment on an NLB cluster, you must configure view state validation so that users can view interactive HTML reports. You must do this for the report server and for Report Manager. View state validation is controlled by the ASP.NET. By default, view state validation is enabled and uses the identity of the Web service to perform the validation. However, in an NLB cluster scenario, there are multiple service instances and web service identities that run on different computers. Because the service identity varies for each node, you cannot rely on a single process identity to perform the validation. To work around this issue, you can generate an arbitrary validation key to support view state validation, and then manually configure each report server node to use the same key. You can use any randomly generated hexadecimal sequence. The validation algorithm (such as SHA1) determines how long the hexadecimal sequence must be. Generate a validation key and decryption key by using the autogenerate functionality provided by the .NET Framework. (Well, how to generate Validation key using .Net Framework?) In the end, you must have a singl

validation problem

hii design a user register form for my website.in this form i using validation control.for instance : required field validator and compare validator.but i have problem with this controlsi make a Validationgroup for validation with register button.validationgroup is equal for all controls(validations and button).when i dont fill textboxes and i click on the button first run the button function then run validations.where is my problem?this is my html codes:<table class="format">                                <tr>                                    <td colspan="2">                                        <asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Names="Tahoma"                   &

Problem bounding data to

HiI want to find the correct way to bound data to a asp:checkboxI use this checkbox in the itemtemplate of a detailsview and this detailsview is bounded to a linqdatasource.<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="125px" DataSourceID="LinqDataSource2" EnableModelValidation="True"> <Fields> <asp:TemplateField> <ItemTemplate> <table style="width: 60%;"> <tr> <td> <asp:Label ID="Label1" runat="server" Text="<%#Eval("Fname")%>"></asp:Label> </td> <td> <asp:CheckBox ID="CheckBox1" runat="server" Checked="<%#Eval("isActive")%>" /> </td> </tr> </table> </ItemTemplate> </asp:TemplateField>

EMail Validation Problem

Hai friends,         I have to do  validation for E-Mail using JAVA Script,  The Following code was not working, function Valid() { if (ValidateEmail("<%= textBox.ClientID %>") ) { alert ("Correct"); return true ; } else { alert ("Not Correct"); } } function ValidateEmail(email) { var EmaiAddress=document.getElementById(email); var RegExEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/; if(!RegExEmail .test (EmaiAddress )) { return false ; } else { return true ; } } <asp:button id="button" runat="server" OnClientClieck="validateEmail() " >but,This code was working, function ValidateEmail() { var EmaiAddress=document.getElementById("textbox").value; var RegExEmail = /^(?:\w+\.?)*\w+@(?:\w+\.)+\w+$/; if(!RegExEmail .test (EmaiAddress )) { alert("Not Correct"); } else { alert("Not Correct"); } } <asp:button id="button" runat="server" OnClientClieck="validateEmail() " >   Please Fix the solution.  

regarding validation of user information problem


Iam new to asp.net. in my web page iam validating user information such as fname,lname,sex,add and also login (to register to website)information emailid and password . here iwant to check email adrress (availblity) and tht iam doing it fine. but when iam validating all the textbox,which are there before emailid  something like this




login details

emailid:   check (buttonto check email availiblity)


retype password:


iam using validation controls for all the text boxes , when iam using my tab to enter the values it w,l give me alll error messege until i fill it. and when i reach email textbox  and check availblity then i cant check untill i fill the password and retype password texboxes..i can only check the email availblity only when al the fields are valid . but i want to valid the emailid before i could enter password and retype password ? how to do this  pls help me out..

Problem with date validation.


I have the following code:

protected bool ValidGebdat()
    Regex LongDate = new Regex("^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-                   9]|3[01])[- /.][0-9]{4}$");

    string gebDat = GebdatTB.Text;

    string s = gebDat.Trim();

            if (LongDate.Match(s).Success)
                   return true;
                  return false;

Why do I get a return false when I insert "27-02-1970"?

Validation expression problem


Ok, im in the process of updating our member registration form. We have always used this reg. exp. for emails and it works OK:


But I wanted to update it and found this one posted on some forums and on some major sites:


Like this:

<asp:RegularExpressionValidator ID="valEmailCorrect" ForeColor="" runat="server" Display="Dynamic" ControlToValidate="tbemail"  ValidationExpression="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$"></asp:RegularExpressionValidator>

This expression doesent work at all for me, cant enter any mail at all, all mails are rejected?!  Does anyone knows why?

Problem with Report viewer , no data is displayed and report comes out as empty


Hi ,


I have a problem using Report Viewer With SQL Reporting Services 2005.



I had a really weird issue with a ReportViewer.  It would show the little green Loading progress bar image . but it wouldn't show any data, just a white background where the output should be.  I knew the data was there because exporting to Excel or PDF showed the data just fine. 


  The problem is report toolbar is display but NO DATA is displayed and the report comes out as EMPTY .



Thanks in advance..


Can you please help me out in resolving this problem.



Forms Library Changed event and Validation event returns empty string on date picker


Hi there,

I'm trying to do date validation on a date and time picker through code (i want to make sure that the date is later than today and that the next date is at least one day later than that).

But when i try to get the value in the chagned event, i keep getting empty string as value.

What am i doing wrong here??

This is the code:

public void LeaveRequestFrom_Changed(object sender, XmlEventArgs e)
      // Write your code here to change the main data source.
      XPathNavigator xroot = MainDataSource.CreateNavigator();
      XPathNavigator fromdate = xroot.SelectSingleNode(
        "/my:myFields/my:LeaveRequestFrom", NamespaceManager);

      if (fromdate.Value != "")
        //Make sure the from date is in the future
        if (DateTime.Parse(fromdate.Value) < DateTime.Today.AddDays(1))


The world

Problem with Jquery windows modal + Validation Summary


Hi all, 

I have a jquery windows modal with some textboxes and a OK button, i have placed some field validators to 
respective textboxes with ValidationGroup. 

When the windows modal opens, the required field validator are  working when clicking on 

OK button but i cannot to visualize the error summary. 

how can i do to visualize the summary? 

thx in advance!

checkbox and dropdown validation using jquery+asp.net


i have a checkbox and dropdown in a gridview when user selects checkbox only then he can select the dropdown, and the dropdown wil have the values corresponding to the gridview rows count

if user checks two checkbox in a gridview,and  the dropdown value should be diffrent it should be not the same for the selected checkbox

how to achieve this using Jquery and asp.net


gridview checkbox group by problem



i am using this component http://www.agrinei.com/gridviewhelper/gridviewhelper_en.htm and it works great. The problem im facing is that i need to add a checkbox column(added dinamically) and group by that checkbox. I have added the checkbox using:

        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
            OnSorting="GridView2_Sorting" >
                <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:BoundField DataField="BilledBy" HeaderText="BilledBy" SortExpression="BilledBy" />
                        <asp:CheckBox ID="Include" runat="server" Text='<%# Eval("Project") %>' />

And as specified in the link, i use this code to make the grouping:

Problem with future date validation using CompareValidator


Realy simple aspx page:

<asp:TextBox ID="txtExpireDate" runat="server" Width="78px" MaxLength="10" ></asp:TextBox>


Validation problem with EF model, before annotation validation is evaluated


Hi folks, it's me agian with more EF validation issues...

I am developing a web app in Portuguese, using MVC 2 and EF 4 for the model.

I created a MetadataType class to define the model's validation annotations, where I enter my custom Portuguese messages, like this:


public partial class Property { }

public class PropertyMetaData {

[DisplayName("Status do Projeto:")]

[Required(ErrorMessage = "O status do projeto deve ser selecionado.")]

public object PropertyStatus { get; set; }

[RegularExpression (Regular Expression is blocked by ASP.NET Forum to prevent XSS)]

[Range(0.01, 200000.0, ErrorMessage="A área da propriedade, se fornecida deve ser um número decimal entre 0.01 e 200000")]

[DisplayName("Área Registro (ha):")]

public object Area { get; set; }

Area is a double in my Model. If I enter an invalid number for this field, I receive a standard MVC English error message on the error summary section of my page, and the regular express

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend