I have this website that has a MasterPage and some content pages. The MasterPage contains a div that I pop up when the user clicks a 'Log In' link that is also located on the MasterPage. This login form has two textboxes, one for user name and one for password, and when the user submits the form they should be authenticated and there user info inserted in the session. ALL of the code to handle is is located in the MasterPage code behind.
Here is the issue: When the MasterPage click event grabs the text from the textboxes to use in the authentication method, the code sees the text as empty!!!
What am I missing?
Here is the button click code and form that is located on the master page:
ButtonClick:
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.";
}
And here is the 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>
THe txtUserName and txtPassword Text properties are empty though there is text in the box.
Let me know if you need anything else.