Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
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.

JavaScript
function onCheck() {
            var cb1 = document.getElementById('<%=cbRow1.ClientID%>');
            var txt1 = document.getElementById('<%=TextBox1.ClientID%>').value;
            if (txt1.length != 0)
            {
                cb1.checked = true;
                return true;
            }
            else{
                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
Updated 31-Dec-11 0:18am
v2
Comments
Technoses 31-Dec-11 1:26am    
why you are using checkbox?..
what is actually you want to do?..

I would use a RequiredField Validator control. Forget the mess of setting a hidden check box.
 
Share this answer
 
Comments
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.
[no name] 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?
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..
 
Share this answer
 
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900