Click here to Skip to main content
15,922,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friends I got this Error:



Compiler Error Message: 'ASP.login_aspx' does not contain a definition for 'LoginBtn_Click' and no extension method 'LoginBtn_Click' accepting a first argument of type 'ASP.login_aspx' could be found (are you missing a using directive or an assembly reference?)

Source Error:


<asp:Button ID="LoginBtn" ValidationGroup="LoginValidation"
runat="server" Text="Login" onclick="LoginBtn_Click"/><br />


I have a definition for 'LoginBtn_Click'.
Aspx Page Coding
<asp:Button ID="LoginBtn" ValidationGroup="LoginValidation"
runat="server" Text="Login" onclick="LoginBtn_Click"/>


Aspx.cs Page Coding

C#
protected void LoginBtn_Click(object sender, EventArgs e)
     {
         string ConnectionString = ConfigurationManager.ConnectionStrings["BankDatabaseConnectionString"].ConnectionString;
         DataSet myset = new DataSet();
         try
         {
             using (SqlConnection con = new SqlConnection(ConnectionString))
             {
                 using (SqlCommand cmd = new SqlCommand("Select * from Users where Email=@User_ID and Password=@Password", con))
                 {
                     cmd.CommandType = CommandType.Text;
                     cmd.Parameters.Add(new SqlParameter("@User_ID", SqlDbType.VarChar, 200));
                     cmd.Parameters["@User_ID"].Value = UserIdtxt.Text;
                     cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 15));
                     cmd.Parameters["@Password"].Value = Passwordtxt.Text;
                     con.Open();
                     using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
                     {
                         sda.Fill(myset);
                     }

                 }
             }
             if (myset.Tables[0].Rows.Count > 0)
                 LabelMsg.Text = "Login Successful!";
             else
                 LabelMsg.Text = "Incorrect Credentials!";

         }
         catch (Exception ex)
         {
             LabelMsg.Text = "Exception Occured while Saving: " + ex.Message;
         }
     }

 }




Please check it out and help me to resolve this.

What I have tried:

I deleted the LoginBtn_Click Event in aspx.cs Page and Created a New Click Event,but again I got this Error
Posted
Updated 4-Jun-16 20:05pm
v2

1 solution

This not Compile error, Its Run Time error.

Try these steps:

Make sure that aspx and code behind (.cs) are in sync.

right click the page in design view and click "view code" and make sure it goes to the right code behind file, if not then map it to the concerned file in the Page directive.

Delete the existing button and create a new one in mark up or in design view and right click the button -> go to properties -> go to events tab (flash symbol) -> double click the 'Click' row, it will generate an event to the button, now you can clean and build the solution and check, it should work.
 
Share this answer
 
Comments
Member 11804811 5-Jun-16 3:25am    
I tried all these Steps, But Got the same error. I Deleted the existing button and created a new one in design view and created the click Event too.
But got the same Error.
Karthik_Mahalingam 5-Jun-16 3:29am    
Asp website or web application?
Member 11804811 5-Jun-16 3:30am    
Web Application
Karthik_Mahalingam 5-Jun-16 3:39am    
Post your full aspx code
Aspx.cs code and designer.cs
Member 11804811 5-Jun-16 3:58am    
Designer Page:


<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="Login.aspx.cs" Inherits="SclWebsite.WebForm6" %>

<!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">
<!DOCTYPE html>

<html lang="en">

<head>
<title>RaoRamSinghPublicSchool</title>
<link rel="shortcut icon" href=" "/>


<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- CSS -->
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,100,300,500">
<link rel="stylesheet" href="signinassets/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="signinassets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="signinassets/css/form-elements.css">
<link rel="stylesheet" href="signinassets/css/style.css">

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->

<!-- Favicon and touch icons -->

<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">

<style type="text/css">
.style1
{
font-size: large;
}
</style>

</head>

<body background="images/bg1.jpg">

<!-- Top content -->
<div class="top-content">

<div class="inner-bg">
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2 text">

Customer Login


<div class="description">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-sm-offset-3 form-box">
<div class="form-top">
<div class="form-top-left">

 


<p>Enter your username and password to log on:</p>
</div>
<div class="form-top-right">

</div>
</div>
<div class="form-bottom">
<form role="form" action="" method="post" runat="server" class="login-form">
<div class="form-group">
<label class="sr-only" for="form-username">Username</label>
<asp:TextBox ID="UserIdtxt" runat="server" name="form-username" placeholder="Username..." class="form-username form-control" >

</div>
<div class="form-group">
<label class="sr-only"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900