'ASP.login_aspx' does not contain a definition for 'btnSignIn_Click' - I have the function..then wh

Discussion in 'ASP .Net' started by Columbia Pike, Jun 29, 2004.

  1. Hi,

    I'm trying to have a login page; after logging in the user has to see the list of SQL Server Databases available to him/her. I'm always getting the error

    'ASP.login_aspx' does not contain a definition for 'btnSignIn_Click'

    I have the btnSignIn_Click function defined in a codebehind .cs file - The file name is Connect.aspx.cs. I made a DLL and have that DLL in the Bin subfolder (Bin\Connect.dll).

    Here's the command I used for making the dll -

    C:\Inetpub\wwwroot\xml\dotnet>csc /out:Connect.dll /r:System.dll,System.web.dll,System.Data.dll /t:library Connect.aspx.cs

    Here's the code I wrote for Connect.aspx.cs
    /**********************************************************************************/

    using System;
    using System.Web;
    using System.Data.Common;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
    /// <summary>
    /// Description of Class1.
    /// </summary>
    public class Connect : System.Web.UI.Page
    {
    public System.Web.UI.WebControls.TextBox txtLogin;
    public System.Web.UI.WebControls.RequiredFieldValidator RFVLogin;
    public System.Web.UI.WebControls.TextBox txtPassword;
    public System.Web.UI.WebControls.RequiredFieldValidator RFVPassword;
    public System.Web.UI.WebControls.Button btnSignIn;
    public System.Web.UI.WebControls.Label Msg;

    protected void Page_Load(object sender, EventArgs e){
    if(!IsPostBack) {
    Msg.Text = "Welcome. Enter your SQL Server user-name and password.";
    }
    }

    protected void btnSignIn_Click(object Sender, EventArgs e){

    if(Page.IsValid){
    Session["uid"]=txtLogin.Text;
    Session["pwd"]=txtPassword.Text;
    SqlConnection conn = new SqlConnection("server=localhost;uid=" + txtLogin.Text + ";pwd=" + txtPassword.Text);
    try {
    conn.Open();
    SqlCommand strsql = new SqlCommand("SELECT name FROM master.dbo.sysdatabases WHERE has_dbaccess(name) = 1 ORDER BY name ", conn);
    SqlDataReader myreader;
    myreader = strsql.ExecuteReader();
    }
    catch(SqlException sqlerr) {
    Msg.Text=sqlerr.ToString();
    }
    }
    }
    }
    /**********************************************************************************/



    <pre>
    <!--Here's the code page from where I'm referring this codebehind part. login.aspx ------------>


    <%@ Page Language="c#" codebehind="Connect.aspx.cs" Trace="True" %>
    <html>
    <head>
    </head>
    <body style="FONT-FAMILY: arial">
    <form runat="server">
    <h2>Login Page
    </h2>
    <hr size="1" />
    <table>
    <tbody>
    <tr>
    <td>
    Username:</td>
    <td>
    <asp:TextBox id="txtLogin" runat="server"></asp:TextBox>
    </td>
    <td>
    <asp:RequiredFieldValidator id="RFVLogin" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="UserName"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    Password:</td>
    <td>
    <asp:TextBox id="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
    </td>
    <td>
    <asp:RequiredFieldValidator id="RFVPassword" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="UserPass"></asp:RequiredFieldValidator>
    </td>
    </tr>
    </tbody>
    </table>
    <asp:Button id="btnSignIn" onclick="btnSignIn_Click" Text="Sign In" Runat="server"></asp:Button>
    <p>
    <asp:Label id="Msg" runat="server" forecolor="red"></asp:Label>
    </p>
    </form>
    </body>
    </html>



    <!---------------------------------------------------->
    </pre>



    Can you please tell me what is causing that error ? I've been breaking my head asking everyone, and Googling everything I can.


    Thank you.
    Columbia Pike, Jun 29, 2004
    #1
    1. Advertising

  2. You have to rebuild the cs file and copy the builded .dll file in the bin
    sub folder again

    Regards
    Martin

    "Columbia Pike" <> wrote in message
    news:Xns951711551EF08ramprasadrhotmailcom@207.46.248.16...
    > Hi,
    >
    > I'm trying to have a login page; after logging in the user has to see the

    list of SQL Server Databases available to him/her. I'm always getting the
    error
    >
    > 'ASP.login_aspx' does not contain a definition for 'btnSignIn_Click'
    >
    > I have the btnSignIn_Click function defined in a codebehind .cs file - The

    file name is Connect.aspx.cs. I made a DLL and have that DLL in the Bin
    subfolder (Bin\Connect.dll).
    >
    > Here's the command I used for making the dll -
    >
    > C:\Inetpub\wwwroot\xml\dotnet>csc /out:Connect.dll

    /r:System.dll,System.web.dll,System.Data.dll /t:library Connect.aspx.cs
    >
    > Here's the code I wrote for Connect.aspx.cs
    >

    /***************************************************************************
    *******/
    >
    > using System;
    > using System.Web;
    > using System.Data.Common;
    > using System.Data.SqlClient;
    > using System.Data.SqlTypes;
    > /// <summary>
    > /// Description of Class1.
    > /// </summary>
    > public class Connect : System.Web.UI.Page
    > {
    > public System.Web.UI.WebControls.TextBox txtLogin;
    > public System.Web.UI.WebControls.RequiredFieldValidator RFVLogin;
    > public System.Web.UI.WebControls.TextBox txtPassword;
    > public System.Web.UI.WebControls.RequiredFieldValidator RFVPassword;
    > public System.Web.UI.WebControls.Button btnSignIn;
    > public System.Web.UI.WebControls.Label Msg;
    >
    > protected void Page_Load(object sender, EventArgs e){
    > if(!IsPostBack) {
    > Msg.Text = "Welcome. Enter your SQL Server user-name and password.";
    > }
    > }
    >
    > protected void btnSignIn_Click(object Sender, EventArgs e){
    >
    > if(Page.IsValid){
    > Session["uid"]=txtLogin.Text;
    > Session["pwd"]=txtPassword.Text;
    > SqlConnection conn = new SqlConnection("server=localhost;uid=" +

    txtLogin.Text + ";pwd=" + txtPassword.Text);
    > try {
    > conn.Open();
    > SqlCommand strsql = new SqlCommand("SELECT name FROM

    master.dbo.sysdatabases WHERE has_dbaccess(name) = 1 ORDER BY name ", conn);
    > SqlDataReader myreader;
    > myreader = strsql.ExecuteReader();
    > }
    > catch(SqlException sqlerr) {
    > Msg.Text=sqlerr.ToString();
    > }
    > }
    > }
    > }
    >

    /***************************************************************************
    *******/
    >
    >
    >
    > <pre>
    > <!--Here's the code page from where I'm referring this codebehind part.

    login.aspx ------------>
    >
    >
    > <%@ Page Language="c#" codebehind="Connect.aspx.cs" Trace="True" %>
    > <html>
    > <head>
    > </head>
    > <body style="FONT-FAMILY: arial">
    > <form runat="server">
    > <h2>Login Page
    > </h2>
    > <hr size="1" />
    > <table>
    > <tbody>
    > <tr>
    > <td>
    > Username:</td>
    > <td>
    > <asp:TextBox id="txtLogin"

    runat="server"></asp:TextBox>
    > </td>
    > <td>
    > <asp:RequiredFieldValidator id="RFVLogin"

    runat="server" ErrorMessage="*" Display="Static"
    ControlToValidate="UserName"></asp:RequiredFieldValidator>
    > </td>
    > </tr>
    > <tr>
    > <td>
    > Password:</td>
    > <td>
    > <asp:TextBox id="txtPassword" runat="server"

    TextMode="Password"></asp:TextBox>
    > </td>
    > <td>
    > <asp:RequiredFieldValidator id="RFVPassword"

    runat="server" ErrorMessage="*" Display="Static"
    ControlToValidate="UserPass"></asp:RequiredFieldValidator>
    > </td>
    > </tr>
    > </tbody>
    > </table>
    > <asp:Button id="btnSignIn" onclick="btnSignIn_Click" Text="Sign

    In" Runat="server"></asp:Button>
    > <p>
    > <asp:Label id="Msg" runat="server"

    forecolor="red"></asp:Label>
    > </p>
    > </form>
    > </body>
    > </html>
    >
    >
    >
    > <!---------------------------------------------------->
    > </pre>
    >
    >
    >
    > Can you please tell me what is causing that error ? I've been breaking my

    head asking everyone, and Googling everything I can.
    >
    >
    > Thank you.
    >
    Martin Marinov, Jun 29, 2004
    #2
    1. Advertising

  3. If you use OnClick attribute in the page's HTML view, the name is expected
    to be on the page script and not in the code-behind. If you want to use a
    handler in the code-behind, remove OnClick attribute, go to design view and
    double-click the button. The code-behind will open on the right function. Or
    you can select event handler in the button properties panel on Events tab.
    Or you can do it without design view whatsoever. Just go to the code-behind
    and add a line for registering the event-handling method for the Click
    event of the button:
    btnSignIn.Click += new EventHandler(this.btnSignIn_Click);

    When you do it in the design view, this line is added to the automatically
    generated InitializeComponent() method.

    Eliyahu

    "Columbia Pike" <> wrote in message
    news:Xns951711551EF08ramprasadrhotmailcom@207.46.248.16...
    > Hi,
    >
    > I'm trying to have a login page; after logging in the user has to see the

    list of SQL Server Databases available to him/her. I'm always getting the
    error
    >
    > 'ASP.login_aspx' does not contain a definition for 'btnSignIn_Click'
    >
    > I have the btnSignIn_Click function defined in a codebehind .cs file - The

    file name is Connect.aspx.cs. I made a DLL and have that DLL in the Bin
    subfolder (Bin\Connect.dll).
    >
    > Here's the command I used for making the dll -
    >
    > C:\Inetpub\wwwroot\xml\dotnet>csc /out:Connect.dll

    /r:System.dll,System.web.dll,System.Data.dll /t:library Connect.aspx.cs
    >
    > Here's the code I wrote for Connect.aspx.cs
    >

    /***************************************************************************
    *******/
    >
    > using System;
    > using System.Web;
    > using System.Data.Common;
    > using System.Data.SqlClient;
    > using System.Data.SqlTypes;
    > /// <summary>
    > /// Description of Class1.
    > /// </summary>
    > public class Connect : System.Web.UI.Page
    > {
    > public System.Web.UI.WebControls.TextBox txtLogin;
    > public System.Web.UI.WebControls.RequiredFieldValidator RFVLogin;
    > public System.Web.UI.WebControls.TextBox txtPassword;
    > public System.Web.UI.WebControls.RequiredFieldValidator RFVPassword;
    > public System.Web.UI.WebControls.Button btnSignIn;
    > public System.Web.UI.WebControls.Label Msg;
    >
    > protected void Page_Load(object sender, EventArgs e){
    > if(!IsPostBack) {
    > Msg.Text = "Welcome. Enter your SQL Server user-name and password.";
    > }
    > }
    >
    > protected void btnSignIn_Click(object Sender, EventArgs e){
    >
    > if(Page.IsValid){
    > Session["uid"]=txtLogin.Text;
    > Session["pwd"]=txtPassword.Text;
    > SqlConnection conn = new SqlConnection("server=localhost;uid=" +

    txtLogin.Text + ";pwd=" + txtPassword.Text);
    > try {
    > conn.Open();
    > SqlCommand strsql = new SqlCommand("SELECT name FROM

    master.dbo.sysdatabases WHERE has_dbaccess(name) = 1 ORDER BY name ", conn);
    > SqlDataReader myreader;
    > myreader = strsql.ExecuteReader();
    > }
    > catch(SqlException sqlerr) {
    > Msg.Text=sqlerr.ToString();
    > }
    > }
    > }
    > }
    >

    /***************************************************************************
    *******/
    >
    >
    >
    > <pre>
    > <!--Here's the code page from where I'm referring this codebehind part.

    login.aspx ------------>
    >
    >
    > <%@ Page Language="c#" codebehind="Connect.aspx.cs" Trace="True" %>
    > <html>
    > <head>
    > </head>
    > <body style="FONT-FAMILY: arial">
    > <form runat="server">
    > <h2>Login Page
    > </h2>
    > <hr size="1" />
    > <table>
    > <tbody>
    > <tr>
    > <td>
    > Username:</td>
    > <td>
    > <asp:TextBox id="txtLogin"

    runat="server"></asp:TextBox>
    > </td>
    > <td>
    > <asp:RequiredFieldValidator id="RFVLogin"

    runat="server" ErrorMessage="*" Display="Static"
    ControlToValidate="UserName"></asp:RequiredFieldValidator>
    > </td>
    > </tr>
    > <tr>
    > <td>
    > Password:</td>
    > <td>
    > <asp:TextBox id="txtPassword" runat="server"

    TextMode="Password"></asp:TextBox>
    > </td>
    > <td>
    > <asp:RequiredFieldValidator id="RFVPassword"

    runat="server" ErrorMessage="*" Display="Static"
    ControlToValidate="UserPass"></asp:RequiredFieldValidator>
    > </td>
    > </tr>
    > </tbody>
    > </table>
    > <asp:Button id="btnSignIn" onclick="btnSignIn_Click" Text="Sign

    In" Runat="server"></asp:Button>
    > <p>
    > <asp:Label id="Msg" runat="server"

    forecolor="red"></asp:Label>
    > </p>
    > </form>
    > </body>
    > </html>
    >
    >
    >
    > <!---------------------------------------------------->
    > </pre>
    >
    >
    >
    > Can you please tell me what is causing that error ? I've been breaking my

    head asking everyone, and Googling everything I can.
    >
    >
    > Thank you.
    >
    Eliyahu Goldin, Jun 29, 2004
    #3
  4. Columbia Pike

    Jo Inferis Guest

    Eliyahu Goldin wrote:
    > If you use OnClick attribute in the page's HTML view, the name is
    > expected to be on the page script and not in the code-behind.

    That's not actually true. I'm using

    <% Page Inherits="myNamespace.myPage" %>

    with a compiled codebehind page and I can assign event handlers with OnClick
    just fine.

    It seems like InitializeComponent is only there for the designer....

    --
    jo inferis
    Jo Inferis, Jun 29, 2004
    #4
  5. Thank you for the correction about inheritance, you are right.

    InitializeComponent does have a use in run-time. When you add event handlers
    via design view, VisualStudio creates private methods in the code-behind and
    doesn't create OnClick attribute in the aspx. Then it is InitializeComponent
    that actually establishes links between controls and their event handlers.

    Eliyahu

    "Jo Inferis" <> wrote in message
    news:esF$...
    > Eliyahu Goldin wrote:
    > > If you use OnClick attribute in the page's HTML view, the name is
    > > expected to be on the page script and not in the code-behind.

    > That's not actually true. I'm using
    >
    > <% Page Inherits="myNamespace.myPage" %>
    >
    > with a compiled codebehind page and I can assign event handlers with

    OnClick
    > just fine.
    >
    > It seems like InitializeComponent is only there for the designer....
    >
    > --
    > jo inferis
    >
    >
    Eliyahu Goldin, Jun 29, 2004
    #5
  6. Re: 'ASP.login_aspx' does not contain a definition for 'btnSignIn_Click' - I have the function..then why? - FIXED.

    Hello everyone...after your tips I did some more trial and error and now
    the code is working. I'm able to fetch the db list. All I did was replace

    codebehind="Connect.aspx.cs"

    with

    Inherits="MyNS.Connect"

    in the login.aspx page, after including the CodeBehind in a namespace MyNS.
    I'd appreciate any explanation for this difference in behavior.

    Thank you once again for all who responded.
    Columbia Pike, Aug 9, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ashish Kanoongo
    Replies:
    1
    Views:
    611
    Vjekoslav Babic
    Feb 3, 2004
  2. Justin Dutoit
    Replies:
    3
    Views:
    3,499
    =?Utf-8?B?dG9tIHdpc25vd3NraQ==?=
    Oct 7, 2004
  3. Tim Cartwright
    Replies:
    6
    Views:
    4,151
    edusabrz
    Nov 13, 2005
  4. keithb
    Replies:
    2
    Views:
    6,721
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    May 31, 2006
  5. Jason Carlton
    Replies:
    11
    Views:
    246
    Dr J R Stockton
    Dec 8, 2009
Loading...

Share This Page