在asp.net C中按钮点击chk验证# [英] chk validation on button click in asp.net C#

查看:83
本文介绍了在asp.net C中按钮点击chk验证#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI专家,



我有一个注册网页,在这个网页上我有3个文本框和一个提交按钮。

我正在使用用于在数据库中插入这些值的Sqlserver 2005数据库。

当我点击提交按钮时,这些值正在成功存储。



到此为止,它工作正常。



现在我的要求是,



如果我点击提交,文本框是空,它必须显示一条消息,请输入必填字段。



如果文本框中填充了数据,那么当我点击提交按钮时,应该显示。< br $> b $ b



你确定要提交这些数据吗?





如果成功存储在数据库中,显示消息....已成功提交。



请帮助我,我很困惑,谢谢。

HI experts,

I have a registration webpage, In this webpage I have 3 textboxes and a submit button.
am using Sqlserver 2005 database for inserting these values in database.
These values are storing Successfully when i click on Submit button.

Till here, it is working fine.

now my requirement is,

If i click on submit and the textboxes are empty, it must display a message please enter the required fields.

if the textboxes are filled with data then, when i click the submit button this should be displayed.


"Are you sure you want to Submit this data ?"


if Successfully stored in DB, Display a message....Successfully Submitted.

Please help me, am in confuse, thanks.

推荐答案

试试这个



Try this

<head>
<script type="text/javascript">
        function Validate() {
            var txt1 = document.getElementById('TextBox1');
            var txt2 = document.getElementById('TextBox2');
            var txt3 = document.getElementById('TextBox3');
            
            if(txt1.value == '' || txt2.value == '' || txt3.value == '')
            {
                alert('please enter value');
                return false;
            }
            else
            {
                return confirm('Do you want to continue')
            }
        }
    </script>
</head>
<body>
<asp:textbox runat="server" txt="valid" id="TextBox1" xmlns:asp="#unknown"></asp:textbox>
      <asp:textbox runat="server" txt="valid" id="TextBox2" xmlns:asp="#unknown"></asp:textbox>
       <asp:textbox runat="server" txt="valid" id="TextBox3" xmlns:asp="#unknown"></asp:textbox>
    <asp:button runat="server" id="btnSubmit" text="save" xmlns:asp="#unknown">
        OnClientClick="javascript:return Validate()" onclick="btnSubmit_Click" />/<body></body></asp:button></body>


空白字段验证代码:

Code for blank field validations:
<asp:textbox id="TextBox1" value="" xmlns:asp="#unknown"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator3" runat="server" errormessage="" forecolor="red" controltovalidate="TextBox1" validationgroup="A" initialvalue="" xmlns:asp="#unknown">*</asp:requiredfieldvalidator>

<asp:textbox id="TextBox2" textmode="Password" value="" xmlns:asp="#unknown"></asp:textbox>
<asp:requiredfieldvalidator id="RequiredFieldValidator4" runat="server" errormessage="" forecolor="red" controltovalidate="TextBox2" validationgroup="A" initialvalue="" xmlns:asp="#unknown">*</asp:requiredfieldvalidator>

<asp:button id="btn_submit" runat="server" text="Submit" onclick="btn_submit_Click" onclientclick="return confirm('Are you sure you want to enter details?');" validationgroup="A" xmlns:asp="#unknown" />





输入详细信息的代码:



Code for entering details:

protected void btn_submit_Click(object sender, EventArgs e)
{
//You code here
Response.Write("<script type='text/javascript'>");
Response.Write("alert('Your details has been submitted successfully.');");
Response.Write("</script>");
}



问候......:笑:


Regards.. :laugh:


试试这个:



http://www.aspdotnet-suresh .com / 2010/10 / javascript-validations-to-validate-form.html [ ^ ]


这篇关于在asp.net C中按钮点击chk验证#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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