ASP.NET默认按钮和默认焦点不起作用。我的应用程序托管在我的服务器机器上的IIS上。 (Servername说 Server1 )。如果我正在访问机器焦点以外的应用程序URL,并且默认按钮单击工作正常(http://Server1/VPath/Login.aspx)。如果我在服务器中使用localhost访问应用程序URL它工作正常(http://localhost/VPath/Login.aspx)但是当我使用服务器访问URL时,焦点和默认按钮单击(在Enter上)不起作用服务器中的名称。 (HTTP://server1/VPath/Login.aspx)。可能是什么问题?
注意: IE版本在上述所有情况下都相同。
以下是我的代码文件。
<asp:Panel ID="LoginWrapper" runat="server" CssClass="loginWrapper" >
<asp:Login ID="LoginControl" runat="server" meta:resourcekey="LoginResource1"
DisplayRememberMe="false" OnAuthenticate="authenticate">
<LayoutTemplate>
<table>
<tr>
<td>
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName" meta:resourcekey="UserNameLabelResource1"
Text="User Name:"></asp:Label></td>
<td>
<asp:TextBox ID="UserName" runat="server" meta:resourcekey="UserNameResource1"></asp:TextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
ErrorMessage="User Name is required." ToolTip="User Name is required."
meta:resourcekey="UserNameRequiredResource1" Text="*"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password" meta:resourcekey="PasswordLabelResource1"
Text="Password:"></asp:Label></td>
<td>
<asp:TextBox ID="Password" runat="server" TextMode="Password" meta:resourcekey="PasswordResource1"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center; color: red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False" meta:resourcekey="FailureTextResource1"></asp:Literal>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Login"
meta:resourcekey="LoginButtonResource1" /></td>
</tr>
</table>
</LayoutTemplate>
</asp:Login>
</asp:Panel>
protected void Page_Init(object sender, EventArgs e)
{
Response.RedirectLocation = Request.Url.ToString();
// bug#19156 Enter key should Login
LoginControl.Focus();
Page.Form.DefaultButton = ((Button)LoginControl.FindControl("LoginButton")).UniqueID;
}
protected void Page_Load(object sender, EventArgs e)
{
log.Debug("Loading login Page");
try
{
if (Request.QueryString["activity"] != null)
{
string activity = Request.QueryString["activity"].ToString();
switch (activity)
{
case "login":
if (Request.QueryString["Username"] != null)
un = Request.QueryString["Username"].ToString();
if (Request.QueryString["Password"] != null)
pw = Request.QueryString["Password"].ToString();
authenticate(null, null);
break;
}
}
}
catch (ExecutionEngineException ex)
{
}
if (Request.IsAuthenticated && !IsPostBack)
{
Response.Redirect("~/VPath/NotAuthorized.aspx");
}
else if (!IsPostBack)
{
HideTopMenu();
}
}
答案 0 :(得分:1)
我不知道为什么你的代码在从外部访问时不起作用,但我认为问题
与page_init
事件有关。
所以我会建议覆盖它,这也是安全的: -
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
Response.RedirectLocation = Request.Url.ToString();
// bug#19156 Enter key should Login
LoginControl.Focus();
Page.Form.DefaultButton = ((Button)LoginControl.FindControl("LoginButton")).UniqueID;
}