Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I know that it's a basic question about learning ASP.NET, I had searched on Google, StackOverflow, MSDN and CodeProject but nothing was found for my result.

I'm using ASP.NET (C#) to design a page default.aspx within 2 textboxes and a button (username, password and submit).

After login successfull,
C#
Response.Redirect("userprofile.aspx");
will redirect me to the page.

Here is my question: On the page userprofile.aspx, if I click a link to move to default.aspx, "How to change 2 textboxes and a button (disable or disappear on page default.aspx) by 2 links "Hi, username" and "Logout"?

Thank you!
Posted
Updated 25-Mar-15 1:19am
v2
Comments
Nathan Minier 25-Mar-15 7:24am    
In general? Either using a cookie or by using a session. A session is a more common solution, and is exceedingly easy to implement using an if(Session["loginname"] != null) else type constructs.

If you want create simple login panel in c# with two textbox like emailid and password and button control for 'Login' then write below code in button click event in your page

c# Code here

<blockquote class="quote"><div class="op">Quote:</div>string Query = "Select * from tblLogin where emailid='" + txtEmailID.Text + "' and password='" + txtPassword.Text + "'";

SqlDataAdapter adp = new SqlDataAdapter(Query,con);

DataSet ds = new DataSet();

adp.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)

{

lblErrorMsg.Text = "Successfully login";

}

else

{

lblErrorMsg.Text = "EmailID/Password Incorrect";

txtEmailID.Focus();

}</blockquote>



for full details go to this link ....i hope this link will helpful for you

http://aspdotnet-alam.com/Article/how-to-create-login-page-with-proper-validation-and-remember-me-functionality-using-Asp-Net-C-Sharp-1.aspx
 
Share this answer
 
v3
It's better to use asp.net membership, or identity to do these things, but if you are doing this is a learning task then you can store if the user is logged in using the Session. Store their ID or username, and if you need to know if they are logged in check to see if the relevant session variables have a value.

A handy way to show\hide certain elements depending on if someone is authenticated is to use placeholders which you make visible or hidden depending.

XML
<asp:PlaceHolder ID="placeAuthenticated" runat="server" Visible="false">
    <div>Hello <%=Session["Username"] %> (<asp:HyperLink ID="linkLogout" runat="server" NavigateUrl="~/Logout.aspx">logout</asp:HyperLink>)
    </div>
</asp:PlaceHolder>

<asp:PlaceHolder ID="placeAnonymous" runat="server" Visible="true">
    <asp:Button ID="cmdLogin" runat="server" Text="Login" OnClick="cmdLogin_Click" />
</asp:PlaceHolder>


C#
protected void Page_Load(object sender, EventArgs e)
{
    if(!string.IsNullOrWhiteSpace((string)Session["Username"]))
    {
        placeAnonymous.Visible = false;
        placeAuthenticated.Visible = true;
    }
}

protected void cmdLogin_Click(object sender, EventArgs e)
{
    // ensure the user is valid, if so store their username, or userid (or both)
    // in the session
    Session["Username"] = "user1";

    Response.Redirect("test.aspx"); // this page just redirects to itself for simplicity
}
 
Share this answer
 

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