SetFocusOnError不能正常工作 [英] SetFocusOnError doesn't work properly

查看:355
本文介绍了SetFocusOnError不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我有一个表格(asp.net形式)和一些字段(大多数)具有的RequiredFieldValidator。现在我还设置SetFocusOnError =真上所有的人,它工作正常,但所有下拉菜单。让我定义罚款:点击提交按钮后,而其中一个字段为空,浏览器滚动到空场。在下拉菜单的情况下,确实是正确显示字段旁边的错误消息,但是浏览器将不滚动屏幕到外地。我到目前为止阅读栈溢出类似的问题,他们都来使用JavaScript为这个,但我的问题是,我想用asp.net属性用于此。如果它的存在,它应该工作,对不对?除非我这样做是错误的。这里说到的code的工作领域之一:

the problem I have is that I have a form (asp.net form) and some of the fields (most of them) have RequiredFieldValidator. Now I also set SetFocusOnError="true" on all of them and it works fine for all but dropdowns. Let me define fine: after clicking on the Submit button while one of the fields is left blank, browser scrolls up to the empty field. In case of dropdowns the error message is indeed displayed properly next to the field however browser will not scroll up the screen to the field. I've read similar questions on stack overflow so far and they all come to "use JavaScript for this", but my problem is that I want to use asp.net property for this. If it's there it's supposed to work, right? Unless I do it wrong. Here comes the code for one of the working fields:

<div class ="row">
            <div class="three columns medium" align="right">
                <label>Email *</label>
            </div>
            <div class="three columns large">
                <asp:TextBox ID="Email" runat="server"></asp:TextBox>
            </div>
            <div class="six columns large">
                <asp:RequiredFieldValidator ID="EmailRequired" ControlToValidate="Email"
                    ErrorMessage="Please provide us your email address" forecolor="Red" SetFocusOnError="true" runat="server" /><br />
                <asp:RegularExpressionValidator ID="EmailFormat" ControlToValidate="Email"
                    ErrorMessage="Please provide us valid e-mail address" ValidationExpression="^[^\s@]+@[^\s@]+$" forecolor="Red" runat="server" />
            </div>   
        </div>

和不在这儿工作重心的示例:

and here's a sample of not working focus:

<div class ="three columns medium" align="right">
            <asp:DropDownList class="dropdown expand" ID="Location" runat="server">
                <asp:ListItem
                    Enabled="True"
                    Text="Please choose the office location... *"
                    Value=""
                />
                <asp:ListItem
                    Enabled="True"
                    Text="City1"
                    Value="City1"
                />
                <asp:ListItem
                    Enabled="True"
                    Text="City2"
                    Value="City2"
                />
                <asp:ListItem
                    Enabled="True"
                    Text="City3"
                    Value="City3"
                />
            </asp:DropDownList>
        </div>
        <div class ="six columns large">
            <asp:RequiredFieldValidator ID="LocationRequired" ControlToValidate="Location"
                ErrorMessage="Please select the office location" forecolor="Red" SetFocusOnError="true" runat="server" />
        </div>
    <div class ="three columns large"></div>

是我的code错还是我期待它在错误的事情?

Is my code wrong or am I expecting the wrong thing from it?

推荐答案

我怕像jqTransform第三方脚本打破asp.net脚本是设置焦点误差控制的东西。尝试删除第三方脚本和检查。如果他们的事业,那么你需要创造与Java脚本的东西。

I afraid that 3rd party scripts like jqTransform break something in asp.net script that is setting focus on error controls. Try to remove 3rd party scripts and check. If they were cause then you need to invent something with java script

这篇关于SetFocusOnError不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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