using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.WebPartPages; namespace DemoWebPartLibrary { /// <summary> /// Description for WebPart1. /// </summary> [DefaultProperty("Text"), ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"), XmlRoot(Namespace="DemoWebPartLibrary")] public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart { private const string defaultText = ""; private string text = defaultText; [Browsable(true), Category("Miscellaneous"), DefaultValue(defaultText), WebPartStorage(Storage.Personal), FriendlyName("Text"), Description("Text Property")] public string Text { get { return text; } set { text = value; } } /// <summary> /// Render this Web Part to the output parameter specified. /// </summary> /// <param name="output"> The HTML writer to write out to </param> protected override void RenderWebPart(HtmlTextWriter output) { output.Write(SPEncode.HtmlEncode(Text)); } } }
protected override void RenderWebPart(HtmlTextWriter output) { output.Write(SPEncode.HtmlEncode(Text)); } protected override void CreateChildControls() { base.CreateChildControls (); TextBox tb = new TextBox(); tb.Text = "coucou"; }
using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; using System.Xml.Serialization; using Microsoft.SharePoint; using Microsoft.SharePoint.Utilities; using Microsoft.SharePoint.WebPartPages; namespace DemoWebPartLibrary { /// <summary> /// Description for WebPart1. /// </summary> [DefaultProperty("HtmlContent"), ToolboxData("<{0}:WebPart1 runat=server></{0}:WebPart1>"), XmlRoot(Namespace="DemoWebPartLibrary")] public class WebPart1 : Microsoft.SharePoint.WebPartPages.WebPart { private string _htmlContent = ""; // Controles private FreeTextBoxControls.FreeTextBox tBox; [Browsable(false), Category("Miscellaneous"), DefaultValue(""), WebPartStorage(Storage.Shared), FriendlyName("HTML Content"), Description("HTML Content")] public string HtmlContent { get { return _htmlContent; } set { _htmlContent = value; } } protected override void CreateChildControls() { base.CreateChildControls (); // Test si on est en mode dition if (BrowserDesignMode) { // Cration du controle tBox = new FreeTextBoxControls.FreeTextBox(); tBox.ID = "FreeTextBox"; tBox.ButtonFileExtention = "gif"; tBox.ButtonPath = "http://frkusps0/_layouts/images/ftb/office2003/"; // Initialisation du controle tBox.Text = HtmlContent; // Ajout du controle Controls.Add(tBox); // Cration du controle LinkButton lBSave = new LinkButton(); // Initialisation lBSave.Text = "Sauvegarder"; // Gestion des vnements lBSave.Click += new EventHandler(OnSave); // Ajout du controle Controls.Add(new LiteralControl("<br>")); Controls.Add(lBSave); } else { Controls.Add(new LiteralControl(HtmlContent)); } } private void OnSave(object sender, EventArgs args) { // Lors de la demande de sauvegarde HtmlContent = tBox.Text; this.SaveProperties = true; } } }
<SafeControls> <SafeControl Assembly="DemoWebPartLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fb1f6448d3cb82ee" Namespace="DemoWebPartLibrary" TypeName="*" Safe="True" /> </SafeControls>
<?xml version="1.0" encoding="utf-8"?> <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" > <Title>WebPartFreeTextBox</Title> <Description>WebPartFreeTextBox.</Description> <Assembly>DemoWebPartLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fb1f6448d3cb82ee</Assembly> <TypeName>DemoWebPartLibrary.WebPart1</TypeName> <!-- Specify initial values for any additional base class or custom properties here. --> </WebPart>