使用javascript选中或取消选中该复选框,该javascript在单击ASP按钮时即被调用 [英] Check or Uncheck the check box using javascript which is called on click of ASP button

查看:88
本文介绍了使用javascript选中或取消选中该复选框,该javascript在单击ASP按钮时即被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ASP网页中要求在下面有一个文本框,其中有一个ASP按钮,用于将数据插入数据库,该数据需要由用户填充,

单击按钮,以验证他是否使用javascript函数在文本框中填充了数据.
将此对函数的调用作为

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;");



在javascript中验证是否填充了文本框,我需要选中此复选框,否则需要向他显示一条消息以填充该文本框的数据.
在javascript中验证我正在使用的以下功能.



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;
            }
            else{
                alert("Enter text in txt1");
                return false;
            }
        }


并在.cs文件中检查是否选中了隐藏复选框,即我正在将文本框的数据插入数据库中.

但是问题是尽管文本框中有数据,但复选框未被选中,如果我使用调试点看到复选框已选中的值,则为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.

推荐答案

我将使用RequiredField Validator控件.忘记设置隐藏复选框的麻烦.
I would use a RequiredField Validator control. Forget the mess of setting a hidden check box.


代替使用复选框,而使用Hidden Feild ..

如果我们将其设置为false,则该复选框会出现问题,在客户端不会出现此控件.

因此隐藏的字段不会在cleint端,并且可以在服务器或javascript中访问.
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..


检查这些博客
http://www.shiningstar.net/articles/articles/javascript/checkboxes.asp [ ^ ]
http://www.somacon.com/p117.php [
check these blogs
http://www.shiningstar.net/articles/articles/javascript/checkboxes.asp[^]
http://www.somacon.com/p117.php[^]
--NDK


这篇关于使用javascript选中或取消选中该复选框,该javascript在单击ASP按钮时即被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆