Hi all I am relatively new to ASP.NET and would appreciate a little help with a problem I am having. I have a "login" page that (upon validation of username/password) loads up another page. Now I have both these pages (I am using c# btw) written, however I cannot find the (probably one line of) code that I need to get the login screen to launch the second screen. Thanks for your time.

Recommended Answers

All 3 Replies

Sorry forgot to add code for login form

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Button1_Click(Object Source, EventArgs E)
    {
        if(TextBox1.Text=="" && TextBox2.Text=="")
        {
            Label1.Text = "OK";
            
        }
        else
        {
            Label1.Text = "Invalid input";
        }
    }

</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Login Page</title>
    </head>
<body>
    
    <form id="form1" runat="server">
    <div>
        Please enter your credentials:<br />
        <br />
        Username:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <br />
        Password:<asp:TextBox ID="TextBox2" runat="server" TextMode="Password"></asp:TextBox><br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Login" OnClick="Button1_Click" />
        <asp:Label ID="Label1" runat="server"></asp:Label><br />
        <br />
    
    </div>
    </form>
</body>
</html>

you need a response.redirect to the correct page, or server.transfer. However, you should set a unique id in a session variable for the user. Then have a protection script to run on every page much like:

if (session["userid"] == "") { response.redirect("login.aspx") }

great thanks for your help, got it working a treat now !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.