Introduction
This article describes how to move the code files to another assembly from the new added dnn module. It seems simplistic, but I am frequently asked for the explanation and other details.
Background
Moving the code files to another assembly is the general way to protect your code from malicious usage in your delivery, and it is also the common approach for security purpose. I will demonstrate the whole process from the very beginning of creating a dnn web site.
Create a dnn web site
Open the Visual Studio and select File\New Web Site. Select Visual Basic in the language dropdown list and you will be presented with the following screen shot.

Select DotNetNuke Web Application in My Templates section, and then change the location to DNNDemo.
Add a dnn module
Right click and select Add New Item on the pop menu.
And then you will be presentd with the screen shot as follows.
Here we will select C# as the progamming language. So select Visual C# in the language dropdown list and type the module name, as follows.
Now you can find the files generated automatically in the Solution Explorer, and meanwhile you are also notified that you will need to manually rename a couple of folders before you continue. Just follow it and rename the folder DemoModule.
Move the code file
First, let's add a new class library project with C# programming language.
Delete the auto-generated file Class1.cs, and then cut the C# files in the App_Code\DemoModule and DesktopModules\DemoModule and paste in DemoModule project. Don't forget adding the dotnetnuke reference.
Modify the *.ascx file
Open the *.ascx files in the DesktopModules\DemoModule, and remove the setting of CodeFile, as follows:
Apply the modification to all ascx files,and then add the DemoModule assembly reference to this project.
The steps above depart ascx files (the presetation layer) and the cs files(the functionality layer).
The interaction
Since we have departed the C# files from the ascx files, how can we manage the events of the controls or get the inputs of the controls in the presentation layer? Fortunately, asp.net provides us with the method FindControl that makes the code quit simple. The code below will demonstrate a button and how it works.
partial class ViewDemoModule : PortalModuleBase, IActionable
{
private Button Button1
{
get
{
return (Button)FindControl("Button1");
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Button1.Click += new EventHandler(Button1_Click);
}
private void Button1_Click(object sender, EventArgs e)
{
//handle the event of button1
}
}
About the article
This article is quit simple and many aspects have been omitted. It just gives you a glance at the process of departing the C# files from the ascx files. In the following steps, you can add more functionality to the class as you would do with the ascx files.