This simplified Hello World portlet example allows a user to set the message that is displayed within a portlet.
Before writing any code, create a new IDK project as described in Setting Up a Custom .NET IDK Project.
<%@ Page language="c#" CodeFile="portlet.aspx.cs" AutoEventWireup="false" Inherits="HelloWorld.WebForm1" ResponseEncoding="UTF-8"%> <form id="Form1" method="post" runat="server"> <br> <asp:label runat="server" id="settingsDisplay"></asp:label> <br><br> Enter your message:<br> <asp:textbox id="PrefName" runat="server"></asp:textbox> <br><br> <asp:Button id="AddButton" runat="server" Text="Submit" ></asp:Button> <br> </form>The code-behind page instantiates the IDK and uses the IDK Portlet API IPortletRequest object to check for a Portlet setting called "MyPref". If the setting has an associated value, the page sends it back for display. If the user entered a new value in the form, the portlet sends it back for display and uses the IPortletResponse object to store it in the portal database. When the setting value and portlet display are updated, the portal page is refreshed.
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using Plumtree.Remote.Portlet; namespace HelloWorld { /// <summary> /// Summary description for WebForm1. /// </summary> public class WebForm1 : System.Web.UI.Page { //put member variables in protected scope as that is the most //limited scope that the aspx page can see. protected System.Web.UI.WebControls.Label settingsDisplay; protected System.Web.UI.WebControls.TextBox PrefName; protected System.Web.UI.WebControls.Button AddButton; protected Plumtree.Remote.Portlet.IPortletRequest portletRequest; protected Plumtree.Remote.Portlet.IPortletResponse portletResponse; protected string settingKey = "MyPref"; protected string settingValue; private void Page_Load(object sender, System.EventArgs e) { } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form // Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.AddButton.Click += new System.EventHandler(this.AddButton_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void AddButton_Click(object sender, System.EventArgs e) { //get the setting value IPortletContext portletContext = PortletContextFactory.CreatePortletContext(Request,Response); portletRequest = portletContext.GetRequest(); portletResponse = portletContext.GetResponse(); settingValue = portletRequest.GetSettingValue(SettingType.Portlet,settingKey); //set the label with the retrieved value //(if it has already been set) if(null != settingValue) { settingsDisplay.Text = "Old preference value is " + Server.HtmlEncode(settingValue) + "!"; } if (PrefName.Text != "") { settingsDisplay.Text += "\New preference value is " + Server.HtmlEncode(PrefName.Text)+ "!"; portletResponse.SetSettingValue(SettingType.Portlet, settingKey,PrefName.Text); } } } }
After you have completed the portlet code, deploy your custom project as described in Deploying a Custom .NET IDK Project in IIS.