通过在asp.net登录控件中按Enter键登录(Login by hitting enter key in asp.net Login control)

编程入门 行业动态 更新时间:2024-10-24 21:31:06
通过在asp.net登录控件中按Enter键登录(Login by hitting enter key in asp.net Login control)

我必须阅读一百个关于此的论坛和博客文章,所有人都在谈论放置一个Panel并将Default按钮设置为Login按钮,或者在Form中设置Default按钮。 我已经尝试了所有这些以及更多,但没有任何作用。

我的Login控件中有两个LinkBut​​tons,它被转换为模板。 第一个是Login按钮,第二个是注册页面的链接。 当我按Enter键时,Register LinkBut​​ton会触发并重定向到寄存器页面。

我已经尝试在面板上设置默认按钮并将它们放在任何地方,并在Form标签本身中设置默认按钮。 我尝试删除“注册”按钮并设置onclick并调用重定向到注册页面的函数。 这甚至都不起作用,输入键仍然重定向到注册页面。

它们被放置在LayoutTemplate中,如下所示:

<div class="btn-login"> <asp:LinkButton ID="LoginButton" runat="server" CommandName="Login" ValidationGroup="LoginUserValidationGroup" Height="38px" Width="120px"> </asp:LinkButton> </div> <div class="btn-opretbruger"> <asp:LinkButton ID="Register" runat="server" ValidationGroup="LoginUserValidationGroup" Height="38px" Width="120px" PostBackUrl="/Account/registrerbruger.aspx"> </asp:LinkButton> </div>

我读过的所有文章都使用了Button控件,我使用的是LinkBut​​ton。

有任何想法吗?

I must have read a hundred forum and blogposts about this, all talking about placing a Panel and setting the Default button to the Login button, or setting the Default button in the Form. I've tried all this plus lots more, but nothing works.

I have two LinkButtons in my Login control, which is converted to a template. The first is the Login button, the second is a link to a register page. When I hit enter, the Register LinkButton fires and redirects to the register page.

I've tried setting the default button on panels and placing them everywhere and setting the default button in the Form tag itself. I tried removing the Register button and setting an onclick on the and calling a function that redirected to the register page. That didn't even work, and the enter key still redirected to the register page.

They are placed in the LayoutTemplate like this:

<div class="btn-login"> <asp:LinkButton ID="LoginButton" runat="server" CommandName="Login" ValidationGroup="LoginUserValidationGroup" Height="38px" Width="120px"> </asp:LinkButton> </div> <div class="btn-opretbruger"> <asp:LinkButton ID="Register" runat="server" ValidationGroup="LoginUserValidationGroup" Height="38px" Width="120px" PostBackUrl="/Account/registrerbruger.aspx"> </asp:LinkButton> </div>

All the articles I have read used Button controls, and I use a LinkButton.

Any ideas?

最满意答案

任务1)

在页面中添加一些脚本以禁用输入键...

function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type == "text")) { return false; } }

任务2)

添加一些脚本,允许您定位html元素并为其引发事件处理程序

function submitByTarget(event, target) { if (event.keyCode == 13) { jQuery('#' + target.id).click(); } }

任务3)

为您的登录txtbox添加一个事件处理程序,等待命中输入键,并为目标按钮引发正确的.click处理程序...在这种情况下,“登录”

txtLogin.Attributes.Add("onkeypress", "return submitByTarget(event," + btnSearch.ClientID + ");");

Task 1)

Add some scrip to your page to disable the enter key...

function stopRKey(evt) { var evt = (evt) ? evt : ((event) ? event : null); var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); if ((evt.keyCode == 13) && (node.type == "text")) { return false; } }

Task 2)

Add some script that allows you to target a html element and raise the event handler for it

function submitByTarget(event, target) { if (event.keyCode == 13) { jQuery('#' + target.id).click(); } }

Task 3)

Add an event handler for your login txtbox that waits for the enter key to be hit and raises the correct .click handler for the target button...in this case 'login'

txtLogin.Attributes.Add("onkeypress", "return submitByTarget(event," + btnSearch.ClientID + ");");

更多推荐

Login,LinkButton,Register,电脑培训,计算机培训,IT培训"/> <meta name="des

本文发布于:2023-07-31 20:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347276.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   Enter   asp   net   Login

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!