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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:02:38+00:00 2026-06-07T09:02:38+00:00

I’m an C# ASP.NET beginner, so please excuse anything that’s… not quite right! In

  • 0

I’m an C# ASP.NET beginner, so please excuse anything that’s… not quite right!

In short, I want to create a really basic login system: one which runs through a database and uses sessions so that only logged in users can access certain pages. I know how to do most of that, but I’m stuck with querying data with LINQ on the login page.

On the login page, I have a DropDownList to select a username, a Textbox to type in a password and a button to login (I also have a literal for errors). The DropDownList is databound to a datatable called DT_Test. DT_Test contains three columns: UsernameID (int), Username (nchar(30)) and Password (nchar(30)). UsernameID is the primary key.

I want to make the button’s click event query data from the database with the DropDownList and Textbox, in order to check if the username and password match. But I don’t know how to do this…

Current Code (not a lot!):

Front End:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Login Test</title>
</head>
<body>
    <form id="LoginTest" runat="server">
    <div>

        <asp:DropDownList ID="DDL_Username" runat="server" Height="20px" 
            DataTextField="txt">
        </asp:DropDownList>
        <br />
        <asp:TextBox ID="TB_Password" runat="server" TextMode="Password"></asp:TextBox>
        <br />
        <asp:Button ID="B_Login" runat="server" onclick="B_Login_Click" Text="Login" />
        <br />
        <asp:Literal ID="LI_Result" runat="server"></asp:Literal>

    </div>
    </form>
</body>
</html>

Back End:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login_Login_Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Binder();
            }
    }

    private void Binder()
    {
        using (DataClassesDataContext db = new DataClassesDataContext())
        {
            DDL_Username.DataSource = from x in db.DT_Honeys select new { x.UsernameID, txt = x.Username };
            DDL_Username.DataBind();
        }
    }
    protected void B_Login_Click(object sender, EventArgs e)
    {
        if (TB_Password.Text != "")
        {
            using (DataClassesDataContext db = new DataClassesDataContext())
            {

            }
        }

    }
}

I have spent hours searching and trying different code, but none of it seems to fit in for this context.

Anyway, help and tips appreciated, thank you very much!

  • I am aware of security risks etc. but this is not a live website or anything, it is simply for testing purposes as a beginner. *

Updated code:

Back End:

    using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login_Page_Test : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Tester();
        }
    }

    private void Tester()
    {
        using (DataClassesDataContext db = new DataClassesDataContext())
        {
            DDL_Username.DataSource = from x in db.DT_Honeys select new { id = x.UsernameID, txt = x.Username };
            DDL_Username.DataValueField = "id";
            DDL_Username.DataTextField = "txt";
            DDL_Username.DataBind();
        }
    }
    protected void B_Login_Click(object sender, EventArgs e)
    {
        if (TB_Password.Text != "")
        {
            using (DataClassesDataContext db = new DataClassesDataContext())
            {
                DT_Honey blah = new DT_Honey();
                blah = db.DT_Honeys.SingleOrDefault(x => x.UsernameID == int.Parse(DDL_Username.SelectedValue.ToString()));

                if (blah != null)
                {
                    if (TB_Password.Text.ToString().Trim() == blah.Password.ToString())
                    {
                        LI_Result.Text = "Credentials correct.";
                    }
                    else
                    {
                        LI_Result.Text = "Error: credentials are incorrect.";
                }
                }
                else
                {
                    LI_Result.Text = "Error: null value.";
                }

            }
    }

    }
}

Front End:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Logi Page Test</title>
</head>
<body>
    <form id="LoginPageTest" runat="server">
    <div>

    </div>
    <asp:DropDownList ID="DDL_Username" runat="server">
    </asp:DropDownList>
    <br />
    <asp:TextBox ID="TB_Password" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="B_Login" runat="server" onclick="B_Login_Click" Text="Login" />
    <br />
    <asp:Literal ID="LI_Result" runat="server"></asp:Literal>
    </form>
</body>
</html>
  • I have checked the database aspects, and it is all fine in terms of primary key, columns, actual data, and dataclasses.

Same with textbox:

Back End:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Login_Login_Page_2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void B_Login_Click(object sender, EventArgs e)
    {
        if (TB_Username.Text.ToString().Trim() != "" && TB_Password.Text.ToString().Trim() != "")
        {
            using (DataClassesDataContext db = new DataClassesDataContext())
            {
                DT_Honey Login = new DT_Honey();
                Login = db.DT_Honeys.SingleOrDefault(y => y.UsernameID == int.Parse(TB_Username.Text.ToString().Trim()));

                if (Login != null)
                {
                    if (TB_Password.Text.Trim() == Login.Password.ToString().Trim())
                    {
                        LI_Result.Text = "Yeah! The credentials you entered were correct!";
                    }
                }

                else
                {
                    LI_Result.Text = "Oops! There was an error with the credentials you entered; please try again.";
                }
            }
        }

        else
        {
            LI_Result.Text = "Wow! Please fill out <b>both</b> the Username and Password text fields to login; thank you.";
        }
    }
}

Front End:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Login Page 2</title>
</head>
<body>
    <form id="LoginPage2" runat="server">
    <div>

        <asp:TextBox ID="TB_Username" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="TB_Password" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="B_Login" runat="server" onclick="B_Login_Click" Text="Login" />
        <br />
        <asp:Literal ID="LI_Result" runat="server"></asp:Literal>

    </div>
    </form>
</body>
</html>
  • 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-06-07T09:02:40+00:00Added an answer on June 7, 2026 at 9:02 am

    Maybe this will help you?:

    protected void B_Login_Click(object sender, EventArgs e)
        {
            if (TB_Password.Text != "")
            {
                using (DataClassesDataContext db = new DataClassesDataContext())
                {
                    var user = db.DT_Test.SingleOrDefault(x => x.Username == DDL_Username.SelectedText);
    
                    if (user == null) 
                    {
                        // whoops something's wrong (no matching username in db)
                    }
    
                    if (user.Password == TB_Password.Text)
                    {
                        // do something (correct password)
                    }
                    else
                    {
                        // something else (incorrect password)
                    }
                }
            }
    
        }
    

    However, best practice would be to use a standard membership provider for ASP.NET. Then you don’t have to be in the business of setting up your own membership schema in a database. (It looks as though you’re storing passwords in clear text, but a membership provider will fix that and handle the details for you.)

    MSDN Introduction to Membership

    Edit You’ll probably want to change the Binder code so that your drop down items’ IDs match up with the database ID numbers:

    private void Binder()
    {
        using (DataClassesDataContext db = new DataClassesDataContext())
        {
            DDL_Username.DataSource = from x in db.DT_Honeys select new { id = x.UsernameID, txt = x.Username };
            DDL_Username.DataValueField = "id";
            DDL_Username.DataTextField = "txt";
            DDL_Username.DataBind();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.