Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:26:40+00:00 2026-05-27T03:26:40+00:00

I have a working login form. I was just trying to do a simple

  • 0

I have a working login form. I was just trying to do a simple test to see if it worked and it seems to only work when posting back a second time. In other words…

I enter my username/password and push login button, it posts back but doesn’t show i’m logged in.

Upon clicking the button again, reloading, etc. it will postback again with the desired result.

// from my pageload

//System.Threading.Thread.Sleep(new TimeSpan(0, 0, 0, 10)); 
//didn't work

if (PageBase.Account.AuthenticatedUser != null) //if user is logged in...
    formLogin.Attributes.Add("Style", "background-color:Green");
else
    formLogin.Attributes.Add("Style", "background-color:Red");
// just changed the background color. 2nd postback it turns green.

Thanks for your help and input.

EDIT: More code as requested.

public class AccountManager {
    public Website.User AuthenticatedUser {
        get {
            int id = Convert.ToInt32(( (object)HttpContext.Current.Session["user_id"] ?? 
                                       (object)(HttpContext.Current.Request.Cookies["USER_ID"] ??
                                                new HttpCookie("bugfixcookie") { Value = "0"}).Value));
            var user = (from u in new MyWebsiteEntities().Users where u.ID == id select u).FirstOrDefault();
            return user;
        }
    }
    // create user, 
    public bool Login(string username, string password, bool remember) {
        var result = (from u in new MyWebsiteEntities().Users
        where username == u.Username && password == u.Password select u).FirstOrDefault();
        if (result != null) {
            if (remember) HttpContext.Current.Response.Cookies.Add(new HttpCookie("USER_ID", result.ID.ToString()));
            HttpContext.Current.Session["user_id"] = result.ID.ToString();
            return true;
        } else return false;
    }

    public void Logout() {
        HttpContext.Current.Response.Cookies.Remove("USER_ID");
        HttpContext.Current.Session.Remove("user_id");
    }
}

And…

public class PageBase : System.Web.UI.Page
{
    public static AccountManager Account { get { return new AccountManager(); } }
}

Front End

<form runat="server" id="formLogin">
    <asp:TextBox runat="server" ID="textKey" style="display:none" />
    <asp:CheckBox runat="server" ID="checkboxRemember" />
    <div> 
        <span id="un">Username</span><br />
        <asp:TextBox runat="server" ID="textUsername" />
    </div>
    <div> 
        <span id="pw">Password</span><br />
        <asp:TextBox runat="server" ID="textPassword" TextMode="Password" />
    </div>
    <asp:Button runat="server" ID="buttonLogin" OnClick="buttonLogin_click" />
    <asp:Button runat="server" ID="buttonRegister" OnClick="buttonRegister_click" />
</form>

Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:26:41+00:00Added an answer on May 27, 2026 at 3:26 am

    Suggest moving the Page Load Code above to Page_PreRender Event. Reason being that Page Load runs first then Button Events then PreRender. So Page Load populates Variables and Preps the code for work, then the Button event occurs and the Page does work, then when all work is done Pre Render can collect up changed and unchanged information needed to update the page just before it is sent to the browser. This flow would allow the login button to be pressed, login to occur and then the page come back properly formatted. Hope this Helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on login/signup module(FYI no rolls/membership just a simple login form),data flow
I'm working on a simple javascript login for a site, and have come up
Here is my scenario. I have a working login form that functions correctly. I
I have the WordPress Login form working in the front-end of my website, to
I have this very simple login form with user and pass and I need
I have been working with relational databases for sometime, but it only recently occurred
So I'm working with authlogic, and I'm trying to duplicate the login functionality to
I've got my Spring Security custom login form working. It displays errors if the
I'm using PHP 4.3.9, Apache/2.0.52 I'm trying to get a login system working that
I am trying to use a textarea form entry which I have some javascript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.