Created By
DMG Development
As Seen On

Main Page  |  Forums  |  Register  |  Active Topics  |  Members  |  Search

 
Username:
Password:
DMG Forums >> DMG Forums Discussion >> Tutorials & HOWTO Articles >> Creating Custom ASP.NET Pages, Controls, and Modules for DMG Forums
Creating Custom ASP.NET Pages, Controls, and Modules for DMG Forums
Author Topic
grimmeissen


Administrator


Join Date: 8/30/2005
Posts: 656
Location: Cincinnati, Ohio

Posted: 2/17/2006 2:42:03 PM

The DMG Forums core is enough to design web pages with unlimited possibilities, but for those of you who are accomplished .Net developers and wish to build your own modules or controls to include in or with the DMG Forums pages, this tutorial will show you how. These methods are also good for those who would like to build off of the DMG Forums core in order to learn more about how it works or to learn more about ASP.Net and the .Net languages.

grimmeissen


Administrator


Join Date: 8/30/2005
Posts: 656
Location: Cincinnati, Ohio

Posted: 2/17/2006 2:42:18 PM

Creating Custom Pages/Controls For DMG Forums

Before attempting to create custom controls or pages to add to DMG Forums, be sure that the core installation is set up properly and everything is running. You may not want to add markup code to the .aspx pages that come with DMG Forums, as these may need to be replaced with future versions. Your best bet for customization would be to create new .aspx pages with different names and different code-behinds or copy one of the current .aspx pages and add new modules under a different file name.



Creating A Page Using DMG Forums Modules

To create your own ASP.Net web pages that still include the database connectivity and the template layouts of DMG Forums, all you will need to do is to be sure you include references to the DMG Forums controls when building the new file. For example, if you would like to include a login box on a custom page, you would include the registration of the file inc_login.ascx. To include the header/footer information, there are include files called inc_header.ascx and inc_footer.ascx. Download the .txt file below to view a sample web page with nothing but the include files for DMG Forums. You can convert the extension to .aspx in order to run the page in a web browser.

  • DMG Forums Template Page

    As you can see, the includes are in place for displaying the header, footer, and login HTML markup as well as for displaying the Settings information that applies your colors, fonts, and other layout properties from the database. You can easily take this page and add your own markupt HTML or even give the page its own code-behind class for custom actions and it will still maintain the ties to the DMG Forums system from within the include files. You can also remove some of the includes to leave them out, for example delete the reference to inc_login.ascx to not display a login box on this page.



    Creating A Custom Control For DMG Forums

    Besides building your own template pages that call references to DMG Forums controls (i.e. inc_header.ascx), you can also create custom controls of your own to be included anywhere in the application. The text file below shows the basic syntax for a custom user control. The extension can be changed to .ascx in order to open this control from within a .aspx page.

  • Custom Control For DMG Forums

    This custom control can have your own compiled code added to it as well as any HTML markup that you would like to enter. The text file below shows an ASP.Net web page that calls this control. This shows you how to use your control anywhere inside a .aspx page from within the DMG Forums application.

  • Template Page w/ Included Custom Control



    Making Calls To The DMG Forums Database

    When creating custom pages to add on to the DMG Forums core, it may be desirable to connect to your database to read from custom tables you have created or even to read specific data out of the DMG Forums tables. To obtain this functionality, all you need to do is include a reference to the Functions class from within your custom pages or from within your code-behind files and you will have access to all of the global functions that come with the application. A tutorial will be written later to go over all of the functions available in the global functions class. This tutorial will just cover the database functions.

    To include the global functions in one of your own code-behind pages, just insert the following lines of code at the very top of your source pages. You can code your custom pages in VB or C# and they will still be able to read from the global functions.

    VB.Net
    Code:
    		Imports DMGForums.Global

    C#
    Code:
    		using DMGForums.Global;

    Once these import lines are in place at the top of your code, from within any classes in that namespace you can call the global functions provided with the DMG Forums core. The specific functions we will cover in this tutorial are the ones within the Database class. There are two functions available, one for reading from the database and one for writing to the database. These functions will only work from within your code if your source files are being compiled into the same /bin folder as the rest of the DMG Forums code and if the web.config file contains an accurate database connection string.

    Reading Data From Database:
    Code:
    		Database.Read("SQL READ STATEMENT")

    Writing Data To Database:
    Code:
    		Database.Write("SQL WRITE STATEMENT")

    Database.Read returns an OdbcDataReader object that can be used inside your applications, for example the following code would fill a Repeater control with information from the database. This code is written in VB.Net.
    Code:

    Dim Topics as System.Web.UI.WebControls.Repeater
    Topics.DataSource = Database.Read("SELECT * FROM DMG_TOPICS")
    Topics.DataBind()
    Topics.DataSouce.Close()

    Referencing the Topics Repeater control on one of your .aspx pages will display the values returned from the database.



    For most users, the core code and all of the administrative tools will be enough to satisfy. However, for those who want to dive in and develop custom modules or custom actions for their web sites, the methods described in this tutorial are the ways in which we recommend. Future tutorials will describe other functions available to you in the DMG Forums Global namespace.

  • fit2page


    Newbie

    Join Date: 12/29/2006
    Posts: 8

    Posted: 3/15/2007 7:37:43 AM

    Hi there grimmeissen!

    Question: How can I show the active topics on a different page in my website? I want to put them as a user control on my masterpage.

    I tried but it says the class DMGForums.Topics.Active cannot extend Web.UI.UserControl

    Please help!

    Marc


      Copyright DMG Development DMG Forums 3.2