【发布时间】:2009-07-25 00:17:02
【问题描述】:
我有一个包含 MasterPage 和一些内容页面的网站。 MasterPage 包含一个 div,当用户单击同样位于 MasterPage 上的“登录”链接时,我会弹出该 div。此登录表单有两个文本框,一个用于用户名,一个用于密码,当用户提交表单时,他们应该进行身份验证并在会话中插入用户信息。所有要处理的代码都位于后面的 MasterPage 代码中。
问题是:当 MasterPage 点击事件从文本框中抓取文本以用于身份验证方法时,代码将文本视为空!!!
我错过了什么?
这是位于母版页上的按钮点击代码和表单:
按钮点击:
bool IsUserAuthenticated = false;
string userName = txtUserName.Text;
string password = txtPassword.Text;
IsUserAuthenticated = masterDataManager.AuthenticateUser(userName, password);
if (IsUserAuthenticated)
{
Session.Add("UserName", userName);
lblCurrentUserName.Text = "You are logged in as: " + userName;
string script = "<script type=\"text/javascri\">$('#dialogBox').dialog('close');</script>";
if (Page.ClientScript.IsStartupScriptRegistered("closeDialog"))
{
Page.RegisterStartupScript("closeDialog", script);
}
}
else
{
lblLoginError.Text = "Username/Password combination does not exist in the database. Please try again.";
}
这是Div:
<div id="dialogBox" title="Log In">
<table align="center" style="margin-top: 5px; width: 100%" cellpadding="5" cellspacing="5">
<tr>
<td colspan="2">
<asp:Label ID="lblLoginError" runat="server" Text="" CssClass="errorText"></asp:Label>
</td>
</tr>
<tr>
<td class="dialogText">
<asp:Label ID="lblUserName" runat="server" Text="User Name: " ForeColor="#c3c003"></asp:Label>
</td>
<td class="dialogInput">
<asp:TextBox ID="txtUserName" runat="server" BackColor="Black" ForeColor="#c3c003" Width="210px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="dialogText">
<asp:Label ID="lblPassword" runat="server" Text="Password: " ForeColor="#c3c003"></asp:Label>
</td>
<td class="dialogInput">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" BackColor="Black" ForeColor="#c3c003" Width="210px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="dialogInput" colspan="2">
<asp:UpdatePanel runat="server" ID="testupdatepanel">
<ContentTemplate>
<asp:ImageButton ID="btnLogin" runat="server" ImageUrl="~/images/loginout.png" ImageAlign="Right" style="padding-top: 15px;" onclick="btnLogin_Click" />
<asp:ImageButton ID="btnCancel" runat="server" ImageUrl="~/images/cancelout.png" ImageAlign="Right" style="padding-top: 15px;" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
虽然框中有文本,但 txtUserName 和 txtPassword 文本属性为空。
如果您还需要什么,请告诉我。
【问题讨论】:
-
你能发布一些示例代码吗?
标签: asp.net textbox master-pages