ASP.NET C# partial class in separate files not working CS1061

本小妞迷上赌 提交于 2019-12-11 05:46:39

问题


I have an asp.net page called prequal.aspx with a codebehind of prequal.aspx.cs. It works. I want to separate out each client code from this page into their own partial files (to reduce chance of modifying the wrong one by mistake later.) Both .cs files begin as such:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

    public partial class prequal : System.Web.UI.Page
    {

When I put one of the clients code into its own file, it compiles fine but I get the following error when I try to view the page:

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

prequal.aspx has this:

<asp:LinkButton id="lnkLanguage" onclick="lnkLanguage_Click" runat="server" CausesValidation="False">English / En Español</asp:LinkButton>

prequal.aspx.cs has this:

    protected void lnkLanguage_Click()
    {
        // alternate preferred language
        if (Session["lang"].ToString() == "spa")
        {
            Session["lang"] = "eng";
        }
        else
        {
            Session["lang"] = "spa";
        }
        populateQuestions();
    }

populateQuestions() will call other code in prequal.aspx.cs which calls code in prequal-client1.aspx.cs. The code works before I split it up so am I going about creating separate partial class files incorrectly? Or is the issue something else that I am unaware of yet?


回答1:


I believe the signature for lnkLanguage has to be:

protected void lnkLanguage_Click(object sender, EventArgs e)
{
  //...
}


来源:https://stackoverflow.com/questions/13977984/asp-net-c-sharp-partial-class-in-separate-files-not-working-cs1061

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!