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 have started working on a simple XML pull-parser, and as I've just defuzzed
I have this very simple login form with user and pass and I need
I am working on a login system for a client and I have run
I have made an android app which working fine. I implemented the Login functionality
I have working registration script the only problem is that i do not know
So I'm working with authlogic, and I'm trying to duplicate the login functionality to
I am trying to use a textarea form entry which I have some javascript
Can the form-login tag make use of URLs to external resources? I have two
I’ve just upgraded and have a problem. Previously this code was working fine: page

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.