Click here to Skip to main content
13,765,264 members
Rate this:
Please Sign up or sign in to vote.
There is requirement in my ASP web page to have a textbox below that a ASP button is there to insert the data into database which needs to be filled by user,

on click of button verifying whether he filled data in the textbox using javascript function.
this call to function given to button as

Button1.Attributes.Add("onclick", "javascript:if(onCheck()==false)return false;");

In javascript verifying that if the textbox in is filled, there is checkbox i need to check it, else need to display him a message to fill data that textbox.
to verify that in javascript the following function i am using.

function onCheck() {
            var cb1 = document.getElementById('<%=cbRow1.ClientID%>');
            var txt1 = document.getElementById('<%=TextBox1.ClientID%>').value;
            if (txt1.length != 0)
                cb1.checked = true;
                return true;
                alert("Enter text in txt1");
                return false;

and in .cs file checking if the hidden check box is checked i am inserting data of the textbox into database.

But the probelm is that check box is not getting checked though data is there in the text box, if i see the check box checked value using debug point, it is false.

Please suggest me solutions to solve this.
Posted 30-Dec-11 17:37pm
Updated 31-Dec-11 1:18am
Technoses 31-Dec-11 1:26am
why you are using checkbox?..
what is actually you want to do?..
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I would use a RequiredField Validator control. Forget the mess of setting a hidden check box.
Suraj S Koneri 31-Dec-11 3:29am
no i've given just a peice of requirement... actually i 've 5 rows and 6 columns of textboxes and each row textboxes is one group all textboxes in that row is compulsory... if user fills data in 1st row and leaves other row textboxes empty the entered textboxes value needs to fill in to databse.

so in that i used above logic. for that i need solution.
Not Active 31-Dec-11 8:43am
How do you expect to get an accurate answer when you don't give all the information.

RequiredFieldValidator class - "Makes the associated input control a required field."
What part don't you understand? What else are you not telling us?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Instead of using check box use Hidden Feild..

The problem with that Check box if we make it visible false, on client side this control wont come.

so the hidden feild is wont be in cleint side and can access in server or in javascript..
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Suraj S Koneri 31-Dec-11 3:31am
Thanks for solution but 've already searched those links from google. from that my problem not solved.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.181114.1 | Last Updated 2 Jan 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100