Connecting the Login page with database failed

I am trying to connect my database with the login.aspx file, but I keep getting an error:

SqlDataSource1 Type ‘System.Web.UI.WebControls.SqlDataSource’ does not have a public property named “’OnClick’.”

My main body code of my login.aspx file code is:

<div id="pageBody">
                <form id="loginForm" runat="server">
                    <div class="imgcontainer">
                        <img src="/packages/img_avatar2.png" alt="Avatar" class="avatar">
                    <div class="container">
                        <asp:textbox id="usernameLoginTextbox" placeholder="Enter username" runat="server"/>
                        <asp:Label ID="Label1" Visible="false" CssClass="error px-5 py-1" runat="server" Text=""></asp:Label>
                        <asp:textbox type="password" id="passwordLoginTextbox" placeholder="Enter password" runat="server"/>
                        <asp:Label ID="Label2" Visible="false" CssClass="error px-5 py-1" runat="server" Text=""></asp:Label>
                        <asp:Button runat="server" id="loginButton" Text="Log Me In Amigo" OnClick="loginButton_Click" CssClass="cancelbtn"/>
                        <asp:Label ID="success" CssClass="bg-success px-5 py-2" ForeColor="White" Visible="false" runat="server" Text="Label"></asp:Label>
                <asp:SqlDataSource ID="SqlDataSource1" OnClick ="loginButton_Click" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Table]"></asp:SqlDataSource>

And the database query code is:
CREATE TABLE [dbo].[Table]
    [username] NCHAR(50) NULL, 
    [password] NCHAR(15) NULL

Lastly my loginButton_Click code is:
        protected void loginButton_Click(object sender, EventArgs e)
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from login where <a href="" class="__cf_email__" data-cfemail="89fce7e8e4ecb4c9fcfaecfbe7e8e4ec">[email protected]</a> and <a href="" class="__cf_email__" data-cfemail="dfafbeacaca8bbe29fafbeacaca8b0adbb">[email protected]</a>", con);
            cmd.Parameters.AddWithValue("@username", usernameLoginTextbox.Text);
            cmd.Parameters.AddWithValue("@password", passwordLoginTextbox.Text);

            SqlDataReader sdr = cmd.ExecuteReader();

            if (sdr.Read())
                Label1.Visible = false;
                Label2.Visible = false;
                success.Visible = true;
                success.Text = "Login successful";
                Label1.Visible = true;
                Label2.Visible = true;
                Label1.Text = "Username incorrect";
                Label2.Text = "password incorrect";

Does anybody know what the solution of the problem may be or if I can substitute the OnClick with something else?

Thank you in advance.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

<asp:SqlDataSource tag has no OnClick property defined, you need to remove “OnClick =”loginButton_Click” from asp:SqlDataSource tag. Looks like accidental copy paste error, you already have the same onClick inside <asp:Button.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x