Click here to Skip to main content
15,921,660 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using javascript popup window to login page.when user authentication is success.it will close and redirect to parent page.

login.aspx

JavaScript
<script type="text/javascript">

        function CloseWindow() {
            window.opener.location.href = 'parent.aspx';
            window.close();

        }
</script>

ASP.NET
<fieldset class="login">
 
                <asp:Label ID="lblerrormsg" ForeColor="Red" runat="server" Text=""></asp:Label>
 
                <legend>Account Information</legend>
                <table>
                    <tr>
                        <td>
                            <asp:Label ID="Usernamelbl" runat="server" Text="UserName:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtUserName" Width="120px" runat="server" />
                            <asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username" ControlToValidate="txtUserName" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <asp:Label ID="lblpwd" runat="server" Text="Password:"></asp:Label>
                        </td>
                        <td>
                            <asp:TextBox ID="txtPWD" runat="server" Width="120px" TextMode="Password" />
                            <asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD" ErrorMessage="Please enter Password" />
                        </td>
                    </tr>
                    <tr>
                        <td>
 
                        </td>
                        <td>
                            <asp:CheckBox ID="RememberMe" runat="server"/>
                        <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <asp:Button ID="loginbtn" runat="server" Text="LogIn" OnClick="loginbtn_Click" />
                        </td>
                    </tr>
 
                </table>
 
            </fieldset>



codebehind page

C#
if(Membership.ValidateUser(txtUserName.Text,txtPWD.Text)==true)
            {
                Session["username"] = User.Identity.Name;
                FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);

                FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, RememberMe.Checked);
 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "popup", "<script type='text/javascript'>CloseWindow();</script>", true);
}
else
{
msg.Text="invalid username and password";
}


if login success means it will redirect to some other page and window wont close.
Posted
Comments
Karthik_Mahalingam 10-Jan-14 0:39am    
what issue you are facing ??
raj1990m 10-Jan-14 0:52am    
i cant close javascript popup window if login authentication is success and it should redirect to parent page

1 solution

Ok I have tried a sample project which works:


C#
protected void Submit_Click(object sender, EventArgs e)
        {
            bool valid = false;// <-- We will use this to set success flag when e.g. user is authenticated.

            valid = valueTextBox.Text == "1"; // <-- Do your authentication bit here, and set valid/succes flag.

            if (valid)
            {
                ScriptManager.RegisterStartupScript(Page, this.GetType(), "close", "window.close();", true);
            }
            else
            {
                Response.Write("keep open.");// Or do something else
            }
        }
 
Share this answer
 
v2
Comments
raj1990m 11-Jan-14 1:19am    
i want show login page as a popup window...i configured default page in web.config..tell any other solution
raj1990m 16-Jan-14 0:53am    
please reply to this
njammy 16-Jan-14 5:43am    
Please see my updated solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900