在不工作CS1061单独的文件ASP.NET C#局部类 [英] ASP.NET C# partial class in separate files not working CS1061

查看:98
本文介绍了在不工作CS1061单独的文件ASP.NET C#局部类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为prequal.aspx以prequal.aspx.cs的codebehind一个asp.net页面。有用。我想从这个页面的每个客户端code分离出来,进入自己的部分文件(以减少以后修改了错误的错误的机会。)这两个文件的.cs开始这样:

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
    {

当我把客户code一到自己的文件,它编译罚款,但我得到以下错误,当我尝试查看网页:

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'不包含'lnkLanguage_Click',没有扩展方法的定义lnkLanguage_Click'接受的类型'。ASP prequal_aspx'的第一个参数可以找到(是否缺少使用指令或程序集引用?)

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有这样的:

prequal.aspx has this:

< ASP:LinkBut​​ton的ID =lnkLanguage的onclick =lnkLanguage_Click=服务器的CausesValidation =FALSE>英语/ EN西班牙语< / ASP:LinkBut​​ton的>

prequal.aspx.cs有这样的:

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()将调用在调用code $ p中$ pqual-client1.aspx.cs prequal.aspx.cs其他code。在code工作之前,我把它分解了所以我要对错误创建单独的局部类文件?或者是问题别的东西,我的没有不知道?

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?

推荐答案

我相信签名 lnkLanguage 必须是:

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

这篇关于在不工作CS1061单独的文件ASP.NET C#局部类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆