将类库中的类引用给Aspx [英] Refer Class in Class Library to Aspx

查看:68
本文介绍了将类库中的类引用给Aspx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想创建带代码的aspx页面作为类文件,该文件位于类库(即预编译的类)中.

Hi,
i want to create aspx page with code behind as a class file, which is located in class library,ie, precompiled class.

推荐答案

您好,

我认为这实际上是不可能的,但是,您可以创建一个普通的ASPX页面和代码文件,并仅获取要从预编译类继承的代码文件.那应该起作用.只需确保预编译的类像ASPX代码文件类那样从Page继承即可.

ASPX代码文件类声明的示例:
public class MyPage : Page
转到:
public class MyPage : MyLibraryPageClass
并且您的LibraryPageClass继承页面,如下所示:
public class MyLibraryPageClass : Page

希望这会有所帮助,
埃德


示例代码

MyPage.aspx.cs文件:
Hi there,

I don''t think this is actually possible, however, you could create a normal ASPX page and code file and just get the code file to inherit from your pre-compiled class. That ought to work. Just make sure your pre-compiled class inherits from Page like the ASPX code file class does.

Example of ASPX code file class declaration:
public class MyPage : Page
goes to:
public class MyPage : MyLibraryPageClass
and your LibraryPageClass inherits page like so:
public class MyLibraryPageClass : Page

Hope this helps,
Ed


Sample Code

MyPage.aspx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MyPage : MyLibraryPage
{
}



MyLibraryPage.cs文件:



MyLibraryPage.cs file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class LibraryPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Form.InnerHtml = "Hello world!";
    }
}


yeah i too surprised, just look into the code

here is my aspx page without aspx.cs and aspx.designer.cs :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RefereClassLibrary.aspx.cs"

    Inherits="BaseClassLibrary.RefereClassLibrary" %>

<!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">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>



和ClassLibrary中的类:



and class in ClassLibrary:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class LibraryPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Form.InnerHtml = "Hello world!";
    }
}





然后我将我的类库引用到Project.最终得到了解决方案.





and i referred my Class Library to Project.finally got the solution.


这篇关于将类库中的类引用给Aspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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