Onlineatoz.net | ToolBox WepParts Control PropertyGridEditorPart

ToolBox WepParts Control PropertyGridEditorPart

PropertyGridEditorPart Web Server Control

in ASP.NET environment,This article describes you how to work with PropertyGridEditorPart Web Control.The mechanism of PropertyGridEditorPart can provide an editor control that enables users to edit Custom properties on web Part controls and Custom properties on server controls.

The users can edit custom properties sets other than the EditorPart controls, such as the AppearanceEditorPart and BehaviorEditorPart controls, that edit only existing, By using the PropertyGridEditorPart control.

The Web Parts control set contains the following two features:

  • They are helper controls that enable end users to personalize controls on a Web Parts page.
  • They are visible only in certain display modes.

The following properties are respect to the related controls are as follows:

  • String - TextBox
  • Int, Float, Unit - TextBox
  • Boolean - CheckBox
  • Enum - DropDownList
  • DateTime - TextBox
Properties of PropertyGridEditorPart
  • Title property - allows the user to gets or sets the title for a layout control.
  • Display property -Describes the visiblity of the PropertyGridEditorPart control. The PropertyGridEditorPart control is always visible when the page is in edit mode,
Methods of LayoutEditorPart
  • ApplyChanges- Saves the values from a PropertyGridEditorPart control to the corresponding properties. return true when saving is succeed, otherwise false.
  • SyncChanges-Retrieves the property values from a WebPart control and assigns them to the associated PropertyGridEditorPart control.

the following code snippets demonstrates how to work with the PropertyGridEditorPart Control

in .aspx.cs page,

protected void Page_Load(object sender, EventArgs e)
  {
    btn1.Visible = false;
    txt1.Visible = false;
  }

  private static String editControlTitle;
  
  protected void btn1_Click(object sender, EventArgs e)
  {
    editControlTitle = Server.HtmlEncode(txt1.Text);
    pgep1.Title = editControlTitle;
  }

  protected void pgep1_Init(object sender, EventArgs e)
  {
    if (editControlTitle != null)
      pgep1.Title = editControlTitle;
  }  

  protected void pgep1_PreRender(object sender,
    EventArgs e)
  {
    btn1.Visible = true;
    txt1.Visible = true;
  }    

in .aspx page,

   
<%@ register TagPrefix="uc1" 
  TagName="DisplayModeMenuCS" 
  Src="DisplayModeMenuCS.ascx" %>
<%@ register tagprefix="aspSample" 
  Namespace="Samples.AspNet.CS.Controls" 
  Assembly="UserInfoWebPartCS" %>
  
<html>
  <head id="Head1" runat="server">
    <title>
      User Information WebPart with EditorPart
    </title>
  </head>
  <body>
    <form id="form2" runat="server">
      <asp:webpartmanager id="wp1" runat="server"  />
      <uc1:DisplayModeMenuCS ID="DisplayModeMenu1" runat="server" />
      <asp:webpartzone id="zone1" runat="server" >
        <PartTitleStyle BorderWidth=1 
          Font-Names="Verdana, Arial"
          Font-Size="110%"
          BackColor="LightBlue" />
        <zonetemplate>
          <aspSample:UserInfoWebPart 
            runat="server"   
            id="userinfo" 
            title = "User Information WebPart"
            BackColor="Beige" />          
        </zonetemplate>
      </asp:webpartzone> 
      <div>
      <hr />
      <asp:Button ID="btn1" runat="server" 
        Text="Update EditorPart Title" 
        OnClick="btn1_Click" />
      <asp:TextBox ID="txt1" runat="server"></asp:TextBox>
      </div>
      <asp:EditorZone ID="EditorZone1" runat="server">
        <ZoneTemplate>
          <asp:PropertyGridEditorPart ID="pgep1" 
            runat="server" 
            Title="Edit Custom Properties"
            OnPreRender="pgep1_PreRender" 
            OnInit="pgep1_Init" />   
        </ZoneTemplate>
      </asp:EditorZone>
    </form>
  </body>
</html>    
 
Related Links

Posted by: Admin
Posted on: 9/13/2011 at 5:14 AM
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed