• Decrease Text SizeIncrease Text Size

Custom Module Update View

Posted Date: 5/2/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
To Create a custom update view please follow those steps.
Step 1
In Module > Configuration > GridUpdateUrl enter the URL to your custom page.(see header text for more information)

Step 2
Create asp.net page and insert all of the controls you need on this page.


<%@ page language="C#" masterpagefile="~/Console.master" autoeventwireup="true" codefile="CustomUpdateView.aspx.cs" inherits="Centralpoint.WebSite.Console.Custom.Forms._CustomUpdateView" %>

 <asp:content id="cntContent" contentplaceholderid="cphContent" runat="server">
     <cp:formrow id="cfrTitle" runat="server" text="Title">
         <cp:cptextbox id="ctbxTitle" runat="server" /><br />
  </cp:formrow>
     <cp:formrow id="cfrKeywords" runat="server" text="Keywords">
       <cp:cptextbox id="ctbxKeywords" runat="server" rows="5" textmode="multiline" allowcopy="false" />
  </cp:formrow>
     <cp:formrow id="cfrBody" runat="server" text="Body Copy">
       <cp:cptextbox id="ctbxBodyCopy" runat="server" rows="10" textmode="multiline" allowcopy="false" />
  </cp:formrow>
      <cp:formrow id="cfrError" runat="server" text="Error" visible="false">
       <div id="dvError" runat="server"></div>
  </cp:formrow>

     <cp:formfooter id="cbtnCreateTemplateRecord" runat="server"  buttontype="Standard" unselectoncancel="true" cancelbuttontext="Back" oncancelclick="CancelRecord_Click"  submitbuttontext="Update" onsubmitclick="UpdateRecord_Click"  />
 </asp:content>


 
Step 3
Retrieve data from the database populate your controls and implement records update functionality.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.Caching;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.XPath;
using System.IO;
using Centralpoint;
using Centralpoint.Web;
using Centralpoint.Web.Cms;
using Centralpoint.Web.UI;
using Centralpoint.Web.UI.Controls;
using Centralpoint.Web.UI.Console;
using Centralpoint.Web.Site;
using System.Linq;
using System.Xml.Linq;
using System.Xml.Xsl;
using System.Xml.Schema;

namespace Centralpoint.WebSite.Console.Custom.Forms
{

    public partial class _CustomUpdateView : Centralpoint.WebSite.Console.Page
 {
  private Guid _did;

  /// <summary>
  /// This method overrides the functionality of the page pre-initialization.
  /// </summary>
  /// <param name="e">Set to the event arguments.
  protected override void OnPreInit(EventArgs e)
  {
            if (this.CurrentSiteMapNode.Key.Equals("GenericB", StringComparison.CurrentCultureIgnoreCase)) this.VerifyNavigationItemUrl = false;
   base.OnPreInit(e);
   base.MasterPageFile = Page.ResolveUrl("~/Integrations/Centralpoint/Console.master");
  }

  /// <summary>
  /// 
  /// </summary>
  /// <param name="e">
  protected override void OnInit(EventArgs e)
  {
   base.OnInit(e);
  }

  /// <summary>
  /// This method provides the event handler for the page load event.
  /// </summary>
  /// <param name="sender">Set to the sender of the event.
  /// <param name="e">Set to the event arguments.
  protected void Page_Load(object sender, EventArgs e)
  {
            string did = Request.QueryString["did"];
            if (!did.IsGuid())
            {
                cfrError.Visible = true;
                dvError.InnerHtml = "The URL must have a valid id of the record.";
                return;
            }
            if (!Page.IsPostBack)
            {
                _did = new Guid(did);
                CpCollection attributes = new CpCollection();
                attributes.Load(AttributesCollection);
                ctbxTitle.Text = attributes.Get("Title");
                ctbxKeywords.Text = attributes.Get("Keywords");
                ctbxBodyCopy.Text = attributes.Get("BodyCopy");
            }

  }


        protected void UpdateRecord_Click(object sender, EventArgs e)
        {
            User user = Management.User;
            CpCollection attributes = new CpCollection();
            attributes.Load(AttributesCollection);
            attributes.Set("Title", ctbxTitle.Text.Trim());
            attributes.Set("Keywords", ctbxKeywords.Text.Trim());
            attributes.Set("BodyCopy", ctbxBodyCopy.Text.Trim());
            Common.Utilities utilities = new Common.Utilities();
            utilities.UpsertDocument(attributes.Serialize(), user.UserId, user.Name, user.IsAncestorAdmin);
            Response.Redirect("/Console/Module.aspx?sn=GenericB");
        }

        protected void CancelRecord_Click(object sender, EventArgs e)
        {

        }

        public string AttributesCollection
        {
            get
            {
                object value = ViewState["AttributesCollection"];
                if (value == null)
                {
                    value = Centralpoint.Utilities.Database.ExecuteScalar(Management.Application.SelectConnectionString, String.Format("SELECT TOP 1 Attributes FROM cpsys_DataCurrent WHERE (DataId = '{0}')", _did));
                    ViewState["AttributesCollection"] = value;
                    return (string)value;
                }
                else
                    return (string)ViewState["AttributesCollection"];
            }
            set { ViewState["AttributesCollection"] = value; }
        }

 }

}




Keywords: Console, grid



Related Taxonomy

Comments:

Be the first to leave a comment.
Please Login to post comments.