0

我想在模块中嵌入一个 C# 类,以便我可以使用按钮和单击事件调用函数。我不知道该怎么做。我已经设法编写了我想使用的类,但是我将代码放在哪里?我在 DNN 中创建了一个模块并得到了这个:

<%@ Control Language="C#" ClassName="MailingSystem" Inherits="DotNetNuke.Entities.Modules.PortalModuleBase" %>
<h1>Congratulations</h1>
<p>You have successfully created your module.  You can edit the source of the module control by selecting the View Source Action from the Action Menu.</p>

<script runat="server">

</script>

我不能把我的代码放在这里,我得到各种关于不允许命名空间的错误,不能用“Using”导入类等等。那我该怎么办?我的课正在工作,我只需要将它包装在一个模块中并将其放在 DNN 页面上。

4

4 回答 4

1

最好从 DotNetNuke 模块模板开始,比如这个。它不像创建一个 aspx 页面那么容易。

于 2011-04-15T10:03:59.197 回答
1

只需双击页面的设计部分,页面加载部分就会出现在页面中,您可以将您的 c# 代码放在那里。

于 2012-02-04T07:31:04.310 回答
1

你可能想做这样的事情:

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        /// code goes here
    }
</script>
于 2012-05-15T16:19:38.980 回答
0

如果您不想走整个模块模板路线。请执行下列操作。

  1. 创建一个 webusercontrol (.ascx)
  2. 转到文件后面的代码 (.ascx.cs) 并更改要继承的类DotNetNuke.Entities.Modules.PortalModuleBase(您需要添加 DotNetNuke.dll 作为参考)
  3. 将您想要的任何控件添加到 ascx 并附加任何事件处理程序。我更喜欢在页面初始化方法中执行此操作

在 ASCX 中:

    <asp:Button ID="btnButton" Text="Click me" runat="server" />

在后面的代码中:

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        btnButton.Click += btnButton_Click;
        // OR
        btnButton.Click += (sender, e)=> { // Button clicked! Do something };

    }

    protected void btnButton_Click(object sender, EventArgs e)
    {
         // Your button has been clicked, Do something

    }
  1. 编译代码

  2. 从项目的 bin 文件夹中获取[yourprojectname].dll文件并将其复制到 DNN 的bin文件夹中。然后,将模块控件 ascx 复制到 DNN 的 DesktopModules 文件夹中的专用文件夹中

示例路径:DesktopModule > YourProjectName > [YourASCXName].ascx

  1. 登录 DNN,转到主机>扩展,然后单击添加扩展。通过向导确保将您的扩展类型设置为模块(DNN 中有许多不同类型的扩展)。

  2. 添加后,您将被带回模块扩展页面。向下滚动并找到您的模块扩展。单击编辑,转到模块定义并添加具有有意义名称的模块定义。

示例:YourProjectNameMainView

  1. 然后,将您的 ASCX 文件添加为该模块扩展的视图。点击保存,设置完成

您应该能够将(非常基本的)模块放在页面上并使用它!

于 2016-02-23T13:38:17.347 回答