提交控制按钮登录时,我打回车我打、按钮

2023-09-02 01:39:25 作者:喂,你這個小騷貨

我上有一个登录控件的ASP.NET网页。当我敲回车,登录按钮不火;而不是页面提交,什么都不做。

I have an ASP.NET web page with a Login control on it. When I hit Enter, the Login button doesn't fire; instead the page submits, doing nothing.

标准的解决方案,这一点,我在网上找到的是封闭的登录控制面板中,然后设置面板默认按钮。但显然,这并不工作这么好,如果页面有一个母版页。我试过设置在code,其默认按钮的控制的.ID,控制的.ClientID和控制的.UniqueID,并在每一种情况下,我得到:

The standard solution to this that I've found online is to enclose the Login control in a Panel, then set the Panel default button. But apparently that doesn't work so well if the page has a master page. I've tried setting the default button in code with control.ID, control.ClientID, and control.UniqueID, and in each case I get:

panelName的defaultButton必须类型IButtonControl的控件的ID。

The DefaultButton of panelName must be the ID of a control of type IButtonControl.

我敢肯定有办法用JavaScript做到这一点,但我真的很想跟普通的旧C#code。如果有可能做到这一点。这可能吗?

I'm sure there's a way to do this with JavaScript, but I'd really like to do it with plain old C# code if possible. Is it possible?

推荐答案

这应该是有帮助的:http://weblogs.asp.net/jgalloway/archive/2007/10/03/asp-net-setting-the-defaultbutton-for-a-login-control.aspx

您可以使用下面的登录控件模板中引用的按钮:

You can use the following to reference the button within the Login control template:

DefaultButton="Login$LoginButton"

基本上,你可以定义的defaultButton不只是在形式层面,也对个人的面板水平,只要焦点在面板中,将用于面板的默认按钮,如果你打回车

Basically, you can define a DefaultButton not just on the Form level, but also on individual Panel level, as long as the focus is within the panel, the default button for the panel will be used if you hit "Enter"