In this tutorial we'll be covering how to use the PortalMessage web control from the Portal Framework (PortalFX). This little jewel is how we standardize the messages presented to users of the portal; everything from success messages to "Hey! Something blew up!" can be shown using the PortalMessage control. So let's get started.
Example of the PortalMessage control being used to show an error:

First, you'll want to add a reference to the file
Passageways.WebControls.dll. If you're using VisualStudio you can simply right click on the References folder of your project, then click "Add Reference". Click the "Browse" tab and locate the file. Click "Ok" when you've got it selected.
Next, you'll want to declare the control in your .aspx page, to do that you'll need to register a TagPrefix so it knows where to get the control from:
<%@ Register TagPrefix="PW" Namespace="Passageways.WebControls" Assembly="Passageways.WebControls" %>
Then, go ahead and declare the PortalMessage control where you want it to be displayed in your .aspx page:
<pw:portalmessage id="myPortalMessage" runat="server"/>
In this case we're using the ID of myPortalMessage, and we will use it to set the properties of the control in our code-behind file. Speaking of properties, there are the usual web control properties available, but the one's we'll focus on are
Text,
Type, and
Visible.
In your code-behind (your .aspx.cs file), you'll need a handle on the control you've just created, and it's a good chance that only these two pages need access to it, so we'll declare it as protected within the class block:
protected PortalMessage DocumentMsg;
Text is the verbiage you want to show to the user. In our example above, the
Text property was set like so in the code-behind file (aspx.cs):
myPortalMessage.Text = "Another document with this same file name has already been uploaded for this product. Please try another file or change an existing document for this product.";
Type is used primarily to set the icon displayed to the user. You have four types that are part of the PortalMessageType class:
- Error - used when something unexpected happened, often times this type is used when catching errors. The icon is a red square with an X in it. Your text will also be colored red.
- Information - this message type is handy when you need to show some help such as how to format a phone number or birth date. The icon is a blue circle with a lower case "i" in the middle.
- Success - typically we'll use this icon a lot when it's time for our performance review, "Look at all the success messages sir!" Actually this message is used a lot when a form was filled out and submitted successfully. The icon is a green circle with a check mark in the middle.
- Warning - we see this message type when there's been some sort of error we've anticipated. As shown above in the example, the user has tried to upload a file that already exists, so we display a warning. If the upload had failed due to network issues we would have displayed an error because that behavior is unexpected. The icon for this message is the yellow triangle with an exclamation mark.
To set this property, you could do something like this:
myPortalMessage.Type = PortalMessageType.Warning;
Lastly there's the Visibility property. Lots of times I'll show a message to the user, then I want that message to go away when they leave the page, click cancel, or try to start over. I don't want to clear the text and type every time, leaving some trailing HTML elements, so instead I simply set the Visibility to do the job:
myPortalMessage.Visibility = true;
At this point you should have a clean message on your page looking like the example above. I would say that it's time to celebrate your PortalMessageType.Success, but we've been PortalMessageType.Warning you about too much of that at work :)
Labels: Portal Framework, Tutorials