Optionally provide private feedback to help us improve this article...

Thank you for your feedback!


Adding Custom Pages into InstantForum

This article details the steps required to add a custom ASP.NET web form page to your InstantForum web application. In this example our custom page also includes the ViewTopics user control to display a list of topics from a specific forum on the custom page.

You can find a download of the custom page created in thiese steps at the very bottom of this article (MyCustomPage.zip). This examples demonstrates how to add your own page to InstantForum without the InstantForum master page.

If you wish to wrap your custom page within the InstantForum master page please see the download exmaple below (MyCustomPageUsingMaster.zip).

Creating Your Custom Page

1. Open the InstantForum .sln file in Visual Studio. This should open all required projects. Locate the web project within the Visual Studio Solution Explorer. Right click on the web site and Select "Add New Item".

2. Select the Web Form option from the list of available file types and enter a name for you new page. In this example we'll call this MyCustomPage.aspx. Click the Add button to create your new page. This will add 2 files to your web site project. The ASP.NET web page containing the HTML mark-up (MyCustomPage.aspx) and a code-behind file allowing you to programmatically control the page & controls (MyCustomPage.aspx.vb).

3. If you wish to include InstantForum controls on your custom ASP.NET page you'll need to ensure the following...

3a. You include all the required JavaScript & CSS for our controls within your custom ASP.NET page. You will need to add several CSS & JavaScript files to your pages <head> element. You can see example code for this below...

<link href="https://localhost/InstantForum/Skins/classic/styles/core.css" rel="stylesheet" type="text/css" />
<link href="https://localhost/InstantForum/Skins/classic/styles/theme.css" rel="stylesheet" type="text/css" />
<script src="https://localhost/InstantForum/Globalization/en-Us/Strings.js" type="text/javascript"></script>
<script src="https://localhost/InstantForum/js/core.js" type="text/javascript"></script>

3b. In addition many of our controls require a ASp.NET script manager on the page. You will need to add the ScriptManager control to your ASP.NET page within the <form> element as shown below...

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ctlScriptManager" runat="Server"/>

4. To display a list of topics from a particular forum you can use our ViewTopics control. You can include this on your ASP.NET web page through  couple of steps.

4a. Include the required control registration script (the <% Register %> tag) at the top of your ASP.NET page. This can be seen below...

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MyCustomPage.aspx.vb" Inherits="MyCustomPage" %>
<%@ Register tagPrefix="InstantForum" Namespace="InstantASP.InstantForum.UI.Controls" Assembly="InstantASP.InstantForum.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">

....

4b. Add the ViewTopics server control mark-up to your ASP.NET page...

<InstantForum:ViewTopics id="ctlViewTopics" EnableSortOptions="true"  runat="Server">
    <SearchEventArgs ParentID="0" ShowPinnedTopics="True" />
</InstantForum:ViewTopics>   

5. Whilst not strictly required for the purpose of this example you can set-up the ViewTopics control programmatically from your custom pages code-behind. In this example our code-behind is called MyCustomPage.aspx.vb. If we open this file within Visual Studio you'll notice it contains very little code....

Partial Class MyCustomPage
    Inherits System.Web.UI.Page

End Class

At this stage the code-behind file is simply a place holder for our code.

6. Next we'll want to set-up our ViewTopics control programatically from our code-behind. To do this we'll need to first add an event in which our code will run, in this example the OnInit event for the page is used. We then find the ViewTopics control on the page and set it's various properties to control the data displayed within this control as shown below..

Partial Class MyCustomPage
    Inherits InstantASP.InstantForum.UI.Base.Page

    Protected Overrides Sub OnInit(ByVal e As System.EventArgs)
    
        ' setup view topics to load topics from forum ID 2
        Dim ctlViewTopics As InstantASP.InstantForum.UI.Controls.ViewTopics = _
        DirectCast(Page.FindControl("ctlViewTopics"), InstantASP.InstantForum.UI.Controls.ViewTopics)
        ctlViewTopics.SearchEventArgs.EnableRolesCheck = False
        ctlViewTopics.SearchEventArgs.ForumID = 2
        ctlViewTopics.SearchEventArgs.SortBy = "LastPosterDate"
        ctlViewTopics.SearchEventArgs.SortOrder = InstantASP.Common.Enumerations.EnumSortOrder.DESC

        MyBase.OnInit(e)

    End Sub

End Class

 You may notice in the example above we have also updated the pages inherits attribute. You will need to ensure your custom ASP.NET pages inherit from the InstantASP.InstantForum.UI.Base.Page class as opposed to the System.Web.UI.Page class. 

You can set various properties on our ViewTopics control to determine which data is displayed. For example if you wanted to display posts from different forums simply update the ForumID property. To help we've provided some common examples of API usage below...

Show Topics Matching Specific Keywords

ctlViewTopics.SearchEventArgs.Keywords = "Example Keywords"

 Show Topics Matching Specific Tags

ctlViewTopics.SearchEventArgs.Keywords = "MyTag"
ctlViewTopics.SearchEventArgs.SearchWithin = InstantASP.InstantForum.Enumerations.EnumSearchWithin.Tags

Show Top Rated Topics Globally

ctlViewTopics.SearchEventArgs.SortBy = "Rating"
ctlViewTopics.SearchEventArgs.SortOrder = InstantASP.Common.Enumerations.EnumSortOrder.DESC

Show Top Rated Topics in specific forum

You can determine the forum ID by looking within your InstantForum_Forums database table.

ctlViewTopics.SearchEventArgs.ForumID = 4
ctlViewTopics.SearchEventArgs.SortBy = "Rating"
ctlViewTopics.SearchEventArgs.SortOrder = InstantASP.Common.Enumerations.EnumSortOrder.DESC

Other

To use your own custom title for the ViewTopics control you can set the TextNonLocalized property as shown below...

ctlViewTopics.TextNonLocalized = "My List Of Topics"

That's It!

We hope this article has helped. If you require further assistance of specific code examples please don't hesitate to open a support ticket or contact us. We would be delighted to assist.