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

Thank you for your feedback!


Adding custom user controls to InstantForum

You may wish to add your own custom C# or VB.NET ASP.NET user controls into a InstantForum page. This is helpful if you wish to execute custom server side code within your user control and embed this on InstantForum pages.

Adding a Custom User Control

To add a custom user control we would suggest the following...

1. Navigate to your InstantForum installation via Windows Explorer. Open the Skins/{YourSkinName} folder. Where {YourSkinName} is the name of the folder containing your active skin. The default InstantForum skin is contained within the Skins/Classic folder.

2. Create a new folder within the root of your skin folder. Call this "CustomControls". This is simply used to help organize your user control. You should now have the following folder "Skins/{YourSkinName}/CustomControls"
3. The next step is to create your custom user control and save this to the new CustomControls folder. In this example we'll create a simple user control that shows the current authenticated username.

LoggedInUser.ascx

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="LoggedInUser.ascx.vb" Inherits="Skins_InstantASP_CustomControls_LoggedInUser" %>

<asp:Label ID="lblUsername" runat="server" />

LoggedInUser.ascx.vb

Partial Class Skins_InstantASP_CustomControls_LoggedInUser
Inherits System.Web.UI.UserControl

Private forumContext As InstantASP.InstantForum.HttpContext.ForumContext = _
InstantASP.InstantForum.HttpContext.ForumContext.Current

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

lblUsername.Text = forumContext.CurrentUser.Username

End Sub

End Class

4. Once you've created your custom user control you can add this to any InstantForum skin file. For example to add your custom user control to the InstantForum homepage simply open Skins/{YourSkinName}/Default.ascx

To add your user control to the InstantForum homepage you'll need to first register the simple custom user control at the top of the default.ascx file. You can register the user control like you would with any other ASP.NET user control. For example...

<%@ Register Src="CustomControls/LoggedInUser.ascx" TagPrefix="uc1" TagName="LoggedInUser" %>

The important attribute here is the "Src" attribute. You must ensure this path is correct. You will receive an error at run-time if the "Src" attribute points to a file or folder that does not exist.

Once you've registered the user control at the top of default.ascx you can now include this within the default.ascx file. To control where your user control appears simply add the user control as shown below to an appropriate place within the default.ascx mark-up.

<uc1:loggedinuser runat="server" id="LoggedInUser" />

That's It!

This article shows how to add a basic user control to an existing InstantForum skin file. We hope this was helpful. As always if we can assist further don't hesitate to contact us.