与验证有关 [英] related to validation

查看:57
本文介绍了与验证有关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先我描述一下情况:



从网页上如果我成功插入记录然后没有问题,但如果发生了一些错误,如电子邮件ID已经存在,那么它将重点关注电子邮件ID文本框而不是其他。



在.aspx



firstly I describe situation:

From web page if i insert record successfully then no problem but if some error occur like email id already exist then it focus to the email id text box rather then other.

In .aspx

<asp:TextBox ID="txtEmailId" runat="server" Width="30 %"  />
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" Display="Dynamic" ValidationGroup="addClient"

                                runat="server" ErrorMessage="Please enter Email Id" ControlToValidate="txtEmailId"

                                Width="30 %" SetFocusOnError="true"></asp:RequiredFieldValidator>







在.aspx.cs






In .aspx.cs

catch (SqlException sql)
           {
               //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Email ID already exist !!!');window.location.href='ClientRegistraion.aspx';", true);
               Response.Write("<script language=javascript>alert('Email ID already exist !!!')</script>");
               txtEmailId.Focus();
               RequiredFieldValidator7.Enabled = true;

           }









谢谢提前。





thanks in advance.

推荐答案

我看到你有 SetFocusOnError =true RequiredFieldValidator 。

因为它在验证失败时设置,焦点将设置为验证失败的控件。设置 SetFocusOnError =false,如果你想改变那种行为。
I see that you have SetFocusOnError="true" propery set for RequiredFieldValidator.
since it is set when there is validation failure, focus will be set to the control which failed in validation. Set SetFocusOnError="false", if you wish to change that behaviour.


这篇关于与验证有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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