Reputation: 1317
I want to embed a C# class in a module so that I can call the functions using buttons and click events. I have no idea how to do this. I've managed to write the class I want to use, but where do I put the code? I created a module in DNN and got this:
<%@ 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>
I can't put my code in here, I get all sorts of errors about namespaces not allowed, can't import classes with "Using", and so on. So what am I supposed to do? My class is working, I just need to wrap it in a module and put it on a DNN page.
Upvotes: 0
Views: 2522
Reputation: 1134
If you don't want want to go the whole module template route. Do the following.
DotNetNuke.Entities.Modules.PortalModuleBase
(your will need to add DotNetNuke.dll as reference)In ASCX:
<asp:Button ID="btnButton" Text="Click me" runat="server" />
In Code Behind:
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
}
Compile code
Get [yourprojectname].dll
file from the bin folder of your project and copy it into DNN's bin
folder. Then, copy your module control ascx into a dedicated folder in DNN's DesktopModules Folder
Example Path: DesktopModule > YourProjectName > [YourASCXName].ascx
Login to DNN, go to Host>Extensions and click add extension. Go through the wizard making sure to set your extension type to Module (there are many different types of extensions in DNN).
Once added, you will be be taken back to the module extensions page. Scroll down and find your module extension. Click edit, go to module definitions and add a module definition with a meaningful name.
Example: YourProjectNameMainView
You should be able to drop your (VERY BASIC) module on a page and use it!
Upvotes: 0
Reputation: 11
You may want to do something like this:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
/// code goes here
}
</script>
Upvotes: 1
Reputation: 11
simply you can double click on design part of the page , then the page load section will be appear in the page and you can put your c# code there.
Upvotes: 1
Reputation: 104168
It is better to start with a DotNetNuke Module Template, like this one. It isn't as easy as creating an aspx page.
Upvotes: 1