Developer forum

Forum » Development » How to save HTML in a paragraph module.

How to save HTML in a paragraph module.

Martin Nielsen
Reply
Hi DW,

I'm trying to create a modul where a user can enter HTML in a textarea on a paragraph module, and i want that exact code rendered to my frontend.

My problem is that when i save my HTML, it seems that DW messes it up before it hits the database.

If i save this HTML in my field:
<node attr="value">InnerText</node>
This is what is saved to the ParagraphModuleSettings field in my database :

Notice that my " is gone.
<myfield>&lt;node attr=value&gt;InnerText&lt;/node&gt;</myfield>
My module has to "moved" the inserted HTML from the textarea as is, to the frontend, no changes made to it what so ever.

How can this be done?

Regards
 Martin

Replies

 
Morten Snedker
Reply
 Hi Martin,

Since the content is saved to the ParagraphModuleSettings - which is a lump of XML - obviously we have to parse what goes to this field to avoid ending up with invalid XML. So, you can't do what you want by saving to this column of the Paragraph table.

But a workaround is possible. In the aspx (being your paragraph module), save your module values to your own custom table. The table would have the ParagraphID for identification, and you would then have one column for each module setting. On the Load() part of the aspx (code behind), instead of loading via the Properties object, you'd just load the values from your custom table.

Let me know if it makes sense!

/Snedker



 
Christoffer Andersen
Reply
Greetings, I have taken over on the problem Martin was working on, and when trying to save to my custom table, it seems i need to make a notification subscriber, and the most suitable subscriber seems like Dynamicweb.Notifications.Standard.Paragraph.Saved.

However this notification  is launched I can't acces the values of my fields with a request, ex HttpContext.Current.Request["myKey"] where mykey is the name of a textbox I only get null. Is there another step where I should fiddle with the save for the paragraph. I can't do it on my customModule_Edit.aspx.cs since there is not made a postBack

Regards

Christoffer
 

 
Morten Snedker
Reply
 Hi Christoffer,

The notification way is not the way for you to go.

Could you please post the content of the Edit-page - both the html and the codebehind.

/Snedker
 
Christoffer Andersen
Reply
The aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MetaManager_Edit.aspx.cs" Inherits="MetaManager.MetaManager_Edit" ValidateRequest="false" %>
<%@ Register Assembly="Dynamicweb.Controls" Namespace="Dynamicweb.Controls" TagPrefix="dw" %>

<dw:ModuleHeader ID="ModuleHeader1" runat="server" ModuleSystemName="MetaManager" />
<input name="MetaManager_Settings" type="hidden" value="contentAlways,contentGroup,contentGroupShowOnProduct,contentProduct,contentNews" />
<table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
	<tr>
		<td>
		<dw:GroupBoxStart ID="GroupBoxStart2" runat="server" Title="HTML"/>
		<table cellpadding="2" cellspacing="0" border="0">
      <tr>
        <td colspan="2">
          This module adds content just before &lt;/head&gt;, for at list of availabe tags, use &lt;!--@Co3TemplateTags--&gt;.<br />
          (A list of tags will appear in HTML header)<br />
          Module is context sensitive. Depending on the querystring, content from the different textareas will be parsed and added.
        </td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;   
        </td>
      </tr>
			<tr>
				<td valign="top"><b>Always</b> rendered</td>
				<td>
          <textarea class="std" style="width: 400px; height: 60px;" name="contentAlways" id="contentAlways" runat="server"></textarea>
				</td>
			</tr>
      <tr>
        <td colspan="2">&nbsp;   
        </td>
      </tr>
      <tr>
				<td valign="top">Rendered when <b>GroupID</b> is in URL</td>
				<td>
          <textarea class="std" style="width: 400px; height: 60px;" name="contentGroup" id="contentGroup" runat="server"></textarea><br />
          <input type="checkbox" name="contentGroupShowOnProduct" id="contentGroupShowOnProduct" runat="server" value="true" /> <label for="contentGroupShowOnProduct">Only show GroupID content when ProductID is <b>NOT</b> in url</label>
				</td>
			</tr>
      <tr>
        <td colspan="2">&nbsp;   
        </td>
      </tr>		
      <tr>
				<td valign="top">Rendered when <b>ProductID</b> is in URL</td>
				<td>
          <textarea class="std" style="width: 400px; height: 60px;" name="contentProduct" id="contentProduct" runat="server"></textarea>
				</td>
			</tr>		
      <tr>
        <td colspan="2">&nbsp;   
        </td>
      </tr>
      <tr>
				<td valign="top">Rendered when <b>NewsID</b> is in URL</td>
				<td>
          <textarea class="std" style="width: 400px; height: 60px;" name="contentNews" id="contentNews" runat="server"></textarea>
				</td>
			</tr>				
		</table>
		<dw:GroupBoxEnd ID="GroupBoxEnd2" runat="server" />		
		</td>
	</tr>
</table>
the code behind :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dynamicweb;
using System.Data;

namespace MetaManager
{
  public partial class MetaManager_Edit : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      int ParagraphID = Base.ChkNumber(Base.Request("ID"));
      if (ParagraphID > 0)
      {
        Dynamicweb.Properties properties = Base.GetParagraphModuleSettings(ParagraphID, true);

        using (IDbConnection con = Database.GetConn("Dynamicweb.mdb"))
        {
          using (DAL.DataDataContext db = new DAL.DataDataContext(con))
          {
            var metaManager = (from c in db.Co3_MetaManagers
                               where c.ParagraphId.Equals(ParagraphID)
                               select c).FirstOrDefault();
            
            //load data from custom db
            if (metaManager != null)
            {
              contentAlways.Value = metaManager.AlwaysRendered;
              contentGroup.Value = metaManager.GroupIdRendered;
              contentProduct.Value = metaManager.ProductIdRendered;
              contentNews.Value = metaManager.NewsIdRendered;
              if (properties.get_Value("contentGroupShowOnProduct").Length > 0)
                contentGroupShowOnProduct.Checked = true;
            }

            if (IsPostBack)
            {
              //store data in custom db
              var req = HttpContext.Current.Request;
              if (metaManager == null)
              {
                metaManager = new DAL.Co3_MetaManager();
                metaManager.ParagraphId = ParagraphID;
                db.Co3_MetaManagers.InsertOnSubmit(metaManager);
              }
              metaManager.AlwaysRendered = req["contentAlways"];
              metaManager.GroupIdRendered = req["contentGroup"];
              metaManager.ProductIdRendered = req["contentProduct"];
              metaManager.NewsIdRendered = req["contentNews"];
              db.SubmitChanges();
            }
          }
        }
      }
    }
  }
}

Cheers

Christoffer

 
Morten Bengtson
Reply
This post has been marked as an answer
Maybe you could try using a user control as described here: http://devierkoeden.com/articles/custom-modules-part-2-a-using-user-controls-for-the-edit-page.aspx

And then just store the control values...

metaManager.AlwaysRendered = contentAlways.Value;

/Morten

Votes for this answer: 0
 
Morten Snedker
Reply
Hi Christoffer,

There's not much to add, other than what Bengtson suggested: use standard controls and get/set values from you custom table.

/Snedker
 
Christoffer Andersen
Reply
It solved the problem making a usercontrol, and then a save button to force postbacks, thanks for the help :)

 

You must be logged in to post in the forum