| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1579 人关注过本帖
标题:单击重置按钮时怎么先触发验证控件啊
只看楼主 加入收藏
sandi
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-10-31
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
单击重置按钮时怎么先触发验证控件啊
单击重置按钮时为什么会先触发验证控件啊 而不是直接清除内容重置啊 大侠帮我看看
前台代码:
<td align="right" class="style5">
                        用户名:</td>
                    <td align="left">
                        <asp:TextBox ID="tb_name" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                            ControlToValidate="tb_name" ErrorMessage="用户名不能为空!"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                        用户密码:</td>
                    <td align="left">
                        <asp:TextBox ID="tb_pwd" runat="server" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                            ControlToValidate="tb_pwd" ErrorMessage="密码不能为空"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                        确认密码:</td>
                    <td align="left">
                        <asp:TextBox ID="tb_pwdsure" runat="server" TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                            ControlToValidate="tb_pwdsure" ErrorMessage="**"></asp:RequiredFieldValidator>
                        <asp:CompareValidator ID="CompareValidator1" runat="server"
                            ControlToCompare="tb_pwd" ControlToValidate="tb_pwdsure" ErrorMessage="密码不一致"></asp:CompareValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                        真实姓名: </td>
                    <td align="left">
                        <asp:TextBox ID="tb_tname" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                         Email: </td>
                    <td align="left">
                        <asp:TextBox ID="tb_email" runat="server"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
                            ControlToValidate="tb_email" ErrorMessage="Email不能为空"></asp:RequiredFieldValidator>
                        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
                            ControlToValidate="tb_email" ErrorMessage="*"
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                        性别:</td>
                    <td align="left">
                        <asp:RadioButtonList ID="Rblsit" runat="server" RepeatDirection="Horizontal"
                            Width="92px">
                            <asp:ListItem Selected="True">男</asp:ListItem>
                            <asp:ListItem>女</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                        出生日期:</td>
                    <td align="left">
                        <asp:TextBox ID="tb_bth" runat="server"></asp:TextBox>
                  
                    </td>
                </tr>
                <tr>
                    <td align="right" class="style5">
                        电话号码:</td>
 <td align="center" class="style8">
            <asp:Button ID="tb_tjiao" runat="server" Text="提交" onclick="tb_tjiao_Click" />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="tb_reset" runat="server" Text="重置" UseSubmitBehavior="False"
                onclick="tb_reset_Click" />
        </td>
后台代码:
protected void tb_reset_Click(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            tb_email.Text = "";
            tb_name.Text = "";
            tb_pwd.Text = "";
            tb_bth.Text = "";
            tb_phone.Text = "";
            tb_pwdsure.Text = "";
            tb_tname.Text = "";
        }
    }
搜索更多相关主题的帖子: 验证 触发 按钮 控件 单击重 
2009-11-17 16:17
夜龙魂
Rank: 2
等 级:论坛游民
帖 子:130
专家分:65
注 册:2009-9-24
收藏
得分:10 
因为验证控件是提交到服务器触发的

比的按钮其实都是一样的你只是把名字换了丢一个button 把名字换成提交或者重直但是他原本还是button没什么不同
都是要到服务器所以都会激发验证控件

你可以在重直的按钮下看看属性有个是不回发到服务器设置成false或者在后台第一次加载写这段代码this.tb_reset.CausesValidation = false;

[ 本帖最后由 夜龙魂 于 2009-11-18 11:33 编辑 ]
2009-11-18 11:05
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:10 
将所有的确asp:text改成input,直接用html中的reset 按钮,

飘过~~
2009-11-18 12:35
快速回复:单击重置按钮时怎么先触发验证控件啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043539 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved