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 3691946
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:12:19+00:00 2026-05-19T04:12:19+00:00

I have a master page that holds the loginview content that appears on all

  • 0

I have a master page that holds the loginview content that appears on all subsequent pages based on the master page. i have a username control also nested in the loginview to display the name of the user when they are logged in. the code for the loginview from the master page is displayed as follows:

<div class="loginView">
                <asp:LoginView ID="MasterLoginView" runat="server">
                    <LoggedInTemplate>
                        Welcome <span class="bold"><asp:LoginName ID="HeadLoginName" runat="server" /> 
                            <asp:Label ID="userNameLabel" runat="server" Text="Label"></asp:Label></span>!
                    [ <asp:LoginStatus ID="HeadLoginStatus" runat="server" LogoutAction="Redirect" LogoutText="Log Out" LogoutPageUrl="~/Logout.aspx"/> ]
                        <%--Welcome: 
                        <span class="bold"><asp:LoginName ID="MasterLoginName" runat="server" /> </span>!--%>                       
                    </LoggedInTemplate>
                    <AnonymousTemplate>
                        Welcome: Guest
                        [ <a href="~/Account/Login.aspx" ID="HeadLoginStatus" runat="server">Log In</a> ]
                    </AnonymousTemplate>

                </asp:LoginView>
                <%--&nbsp;&nbsp; [&nbsp;<asp:LoginStatus ID="MasterLoginStatus" runat="server" LogoutAction="Redirect" LogoutPageUrl="~/Logout.aspx" />&nbsp;]&nbsp;&nbsp;--%>

            </div>

Since VS2010 launches with a default login page in the accounts folder, i didnt think it necessary to create a separate log in page, so i just used the same log in page. please find the code for the login control below:

 <asp:Login ID="LoginUser" runat="server" EnableViewState="false" RenderOuterTable="false">
    <LayoutTemplate>
        <span class="failureNotification">
            <asp:Literal ID="FailureText" runat="server"></asp:Literal>
        </span>
        <asp:ValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification" 
             ValidationGroup="LoginUserValidationGroup"/>
        <div class="accountInfo">
            <fieldset class="login">
                <legend style="text-align:left; font-size:1.2em; color:White;">Account Information</legend>
                <p style="text-align:left; font-size:1.2em; color:White;">
                    <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User ID:</asp:Label>
                    <asp:TextBox ID="UserName" runat="server" CssClass="textEntry"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" 
                         CssClass="failureNotification" ErrorMessage="User ID is required." ToolTip="User ID field is required." 
                         ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p style="text-align:left; font-size:1.2em; color:White;">
                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                    <asp:TextBox ID="Password" runat="server" CssClass="passwordEntry" 
                        TextMode="Password"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" 
                         CssClass="failureNotification" ErrorMessage="Password is required." ToolTip="Password is required." 
                         ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
                </p>
                <p style="text-align:left; font-size:1.2em; color:White;">
                    <asp:CheckBox ID="RememberMe" runat="server"/>
                    <asp:Label ID="RememberMeLabel" runat="server" AssociatedControlID="RememberMe" CssClass="inline">Keep me logged in</asp:Label>
                </p>
            </fieldset>
            <p class="submitButton">
                <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" 
                    ValidationGroup="LoginUserValidationGroup" onclick="LoginButton_Click"/>
            </p>
        </div>
    </LayoutTemplate>
</asp:Login>

I then wrote my own code for authentication since i had my own database. the following displays the code in the login buttons click event.:

 public partial class Login : System.Web.UI.Page
{
    //create string objects
    string userIDStr, pwrdStr;

    protected void LoginButton_Click(object sender, EventArgs e)
    {


        //assign textbox items to string objects
        userIDStr = LoginUser.UserName.ToString();
        pwrdStr = LoginUser.Password.ToString();

        //SQL connection string

        string strConn;
        strConn = WebConfigurationManager.ConnectionStrings["CMSSQL3ConnectionString"].ConnectionString;

        SqlConnection Conn = new SqlConnection(strConn);



        //SqlDataSource CSMDataSource = new SqlDataSource();
       // CSMDataSource.ConnectionString = ConfigurationManager.ConnectionStrings["CMSSQL3ConnectionString"].ToString();


        //SQL select statement for comparison

        string sqlUserData;
        sqlUserData = "SELECT StaffID, StaffPassword, StaffFName, StaffLName, StaffType FROM Staffs";
        sqlUserData += " WHERE (StaffID ='" + userIDStr + "')";
        sqlUserData += " AND (StaffPassword ='" + pwrdStr + "')";

        SqlCommand com = new SqlCommand(sqlUserData, Conn);
        SqlDataReader rdr;
        string usrdesc;
        string lname;
        string fname;
        string staffname;

        try
        {

            //string CurrentData;
            //CurrentData = (string)com.ExecuteScalar();
            Conn.Open();
            rdr = com.ExecuteReader();
            rdr.Read();
            usrdesc = (string)rdr["StaffType"];
            fname = (string)rdr["StaffFName"];
            lname = (string)rdr["StaffLName"];
            staffname = lname.ToString() + " " + fname.ToString();
            LoginUser.UserName = staffname.ToString();
            rdr.Close();

            if (usrdesc.ToLower() == "administrator")
            {

                Response.Redirect("~/CaseAdmin.aspx", false);

             }
             else if (usrdesc.ToLower() == "manager")
             {
                 Response.Redirect("~/CaseManager.aspx", false);
             }
             else if (usrdesc.ToLower() == "investigator")
             {
                 Response.Redirect("~/Investigator.aspx", false);
             }
             else
             {
                 Response.Redirect("~/Default.aspx", false);
             }               


        }
        catch(Exception ex)
        {
            string script = "<script>alert('" + ex.Message + "');</script>";
        }
        finally
        {
            Conn.Close();
        }


    }

My authentication works perfectly and the page gets redirected to the designated destination. However, the login view does not display the users name. i actually cant figure out how to pass the users name that i had picked from the database to the login name control to be displayed.

taking a close look i also noticed the logout text that should be displayed after successful log in does not show. that leaves me wondering if the loggedin template control on the masterpage even fires at all or its still the anonymous template control that keeps displaying.?

How do i get this to work as expected? Please help….

  • 1 1 Answer
  • 1 View
  • 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-19T04:12:19+00:00Added an answer on May 19, 2026 at 4:12 am

    What i know is that Login controls are bound to Fetch data from Membership provider.
    But since you are using your own Login System. It can’t get login controls to show data.

    If you want to allow Login Controls to show data automatically then Use Membership Classes

    http://msdn.microsoft.com/en-us/library/tw292whz.aspx

    or if you want to have your own Login system Then Create a Custom membership provider by Implementing Abstract Class MembershipProvider. heres a good resource on that

    http://www.asp.net/general/videos/how-do-i-create-a-custom-membership-provider

    Another way is to update user information Manually on the controls if you don’t want to use membership provider..

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

Sidebar

Related Questions

I have 2 master pages that are nested.this is main master page code for
I have two pages that inherit from one master page, First.aspx or second.aspx. Navigation
I have a master page that uses @RenderBody to display the current controller\action content.
I have a master page that contains an ASP.NET server side Menu control (System.Web.UI.WebControls.Menu)
I have a master page that gets all its images from a table on
I have a master page that has two content sections like this (left some
I'd like to have a page that uses a child master page, fill in
I have a dropdown on my master page that lets the user switch language
I have a controller's action and view page that uses a master page. The
I have made a web application that uses master page for Login & Logout

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.