就是aspx的附加cs文件中的自定义方法要写成protect,不能private

解决方案 »

  1.   

    protected表示该方法只能被该类及其派生类引用
    而private则表示只能在类的内部使用
      

  2.   

    由于前后台是继承的关系,所以如果是private不能访问
      

  3.   

    没明白问题,你是想说在前台中调用后台写的函数????,页面上又个Inherits="_Default" 属性就表示前台是继承与后台类的
      

  4.   

    楼主回答一楼时说:“我知道那个,我是不知道在这里,都是在一个页面中,不是所一个页面就是一个类吗,怎么这里就不能使用私有呢”
    楼主的这句话里有错,它们不是“都是在一个页面中”
    假设你有一个Default.aspx和Default.aspx.cs
    那么,被编译后的实际情况是:
    Default.aspx变成一个类名为Default_aspx(除非你在page指令中指定了ClassName)的类,在ASP命名空间下,它继承了Default.aspx的page指令中Inherits后的那个类(默认为_Default),你打开Default.aspx.cs后会发现,这个_Default类定义在里面,它继承了System.Web.UI.Page类所以说,如果你在代码分离文件中把方法定为了private,则只能在这个分离文件中相应的类中调用。
      

  5.   

    The difference between an ASP.NET page and a classic ASP page is that in ASP.NET the entire file's contents is parsed into a class definition and then complied into an assembly.ASP.NET 1.0 introduced a mechanism for separating programmatic logic from static page layout called codebehind.
    This technique involves creating an intermediate base class that sits between the Page base class and the machine-generated class from the .aspx file.
    The intermediate base class derives directly from Page, and class generated from the .aspx file derives from the intermediate base class instead of directly from from Page.
    With this technique, you can add fields, methods, and event handlers in your codebehind class and have these features inherited by the class created from the .aspx file, eliminating the need to sprinkle code throught the .aspx file.In ASP.NET 2.0 codebehind model, ASP.NET now will also generate a sibling partial class for your codebehind class that contains protected control member variable declarations. Your class is then complied together with this generated class definition, merged together, and then it becomes the base class for the class generated for the .aspx file.
      

  6.   

    一句话,
    页面和后台类是继承的关系
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>