Microsoft Content Management Server - posting.submit() causes error because it is read only

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > March 2006 > posting.submit() causes error because it is read only





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author posting.submit() causes error because it is read only
James Coleman

2006-03-18, 3:18 am

I am trying to create a template that basically allows a user to edit a class
in which I then serialize into xml and then store into the xmlhtmlplaceholder
of a cms template. When I try to do a posting.submit, I get an error thrown
saying that the object is readonly (even though posting.cansubmit is true).
Any help would be appreciated.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
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 Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.WebControls;
using Allsteel.Library;

public partial class Templates_Product : System.Web.UI.Page
{
private Product product;
private Posting posting;
private Boolean authorMode;
protected void Page_Load(object sender, EventArgs e)
{
this.Master.Page.Title = CmsHttpContext.Current.Posting.DisplayName;
posting = CmsHttpContext.Current.Posting;

WebAuthorContextMode mode = WebAuthorContext.Current.Mode;
if (mode == WebAuthorContextMode.AuthoringNew || mode ==
WebAuthorContextMode.AuthoringPreview || mode ==
WebAuthorContextMode.AuthoringReedit){
authorMode = true;
}
pnlEdit.Visible = authorMode;
pnlPresent.Visible = !authorMode;
product = new Product();

if (Page.IsPostBack)
{
if (Session["Product"] != null)
{
product = (Product)Session["Product"];
}
}
else
{
string xml =
posting.Placeholders["Product"].Datasource.RawContent;
if (xml.Length > 0)
{
product = ProductDAO.Deserialize(xml);
SynchPresentation();
}
}
}
protected void SynchPresentation()
{
if (authorMode)
{
tbName.Text = product.Name;
reOverview.Html = product.OverviewBody;
}
else
{
lblName.Text = product.Name;
litOverview.Text = product.OverviewBody;
}
}
protected void SynchClass()
{
product.Name = tbName.Text;
product.OverviewBody = reOverview.Xhtml;
}
protected void btnSave_Click(object sender, EventArgs e)
{
SynchClass();
Session["Product"] = product;
String xml = ProductDAO.Serialize(product);
posting.Placeholders["Product"].Datasource.RawContent = xml;
if (posting.CanSubmit)
{
posting.Submit();
}
}
}


--
James Coleman
Technical Director
AGENCY.COM [Chicago]
jcoleman@agency.com


Stefan [MSFT]

2006-03-18, 3:18 am

Hi James,

are you in update when clicking this button?

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
Check out the new book as well: Advanced MCMS development:
http://tinyurl.com/8ugwj
----------------------


"James Coleman" <JamesColeman@discussions.microsoft.com> wrote in message
news:F4E524F7-81D1-4A79-BAF4-25EBE6BF7EFC@microsoft.com...
>I am trying to create a template that basically allows a user to edit a
>class
> in which I then serialize into xml and then store into the
> xmlhtmlplaceholder
> of a cms template. When I try to do a posting.submit, I get an error
> thrown
> saying that the object is readonly (even though posting.cansubmit is
> true).
> Any help would be appreciated.
>
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> 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 Microsoft.ContentManagement.Publishing;
> using Microsoft.ContentManagement.WebControls;
> using Allsteel.Library;
>
> public partial class Templates_Product : System.Web.UI.Page
> {
> private Product product;
> private Posting posting;
> private Boolean authorMode;
> protected void Page_Load(object sender, EventArgs e)
> {
> this.Master.Page.Title =
> CmsHttpContext.Current.Posting.DisplayName;
> posting = CmsHttpContext.Current.Posting;
>
> WebAuthorContextMode mode = WebAuthorContext.Current.Mode;
> if (mode == WebAuthorContextMode.AuthoringNew || mode ==
> WebAuthorContextMode.AuthoringPreview || mode ==
> WebAuthorContextMode.AuthoringReedit){
> authorMode = true;
> }
> pnlEdit.Visible = authorMode;
> pnlPresent.Visible = !authorMode;
> product = new Product();
>
> if (Page.IsPostBack)
> {
> if (Session["Product"] != null)
> {
> product = (Product)Session["Product"];
> }
> }
> else
> {
> string xml =
> posting.Placeholders["Product"].Datasource.RawContent;
> if (xml.Length > 0)
> {
> product = ProductDAO.Deserialize(xml);
> SynchPresentation();
> }
> }
> }
> protected void SynchPresentation()
> {
> if (authorMode)
> {
> tbName.Text = product.Name;
> reOverview.Html = product.OverviewBody;
> }
> else
> {
> lblName.Text = product.Name;
> litOverview.Text = product.OverviewBody;
> }
> }
> protected void SynchClass()
> {
> product.Name = tbName.Text;
> product.OverviewBody = reOverview.Xhtml;
> }
> protected void btnSave_Click(object sender, EventArgs e)
> {
> SynchClass();
> Session["Product"] = product;
> String xml = ProductDAO.Serialize(product);
> posting.Placeholders["Product"].Datasource.RawContent = xml;
> if (posting.CanSubmit)
> {
> posting.Submit();
> }
> }
> }
>
>
> --
> James Coleman
> Technical Director
> AGENCY.COM [Chicago]
> jcoleman@agency.com
>
>



James Coleman

2006-03-19, 11:59 am

Thanks Stefan for the response. Sorry about the mulitiple postings, when I
was submitting I was getting an error and I didn't realize my post was making
its way in.

I guess I don't know what object and property you want me to check to see if
I am in "update".

The WebAuthorContext.Current.Mode at the time of the posting.submit() is
WebAuthorContextMode.AuthoringReedit.

I will continue to poke around and try and figure it out myself because I am
assuming you take the weekend off.

~James

--
James Coleman
Technical Director
AGENCY.COM [Chicago]


"Stefan [MSFT]" wrote:

> Hi James,
>
> are you in update when clicking this button?
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> Check out the new book as well: Advanced MCMS development:
> http://tinyurl.com/8ugwj
> ----------------------
>
>
> "James Coleman" <JamesColeman@discussions.microsoft.com> wrote in message
> news:F4E524F7-81D1-4A79-BAF4-25EBE6BF7EFC@microsoft.com...
>
>
>

James Coleman

2006-03-19, 11:59 am

Okay, it looks like the CmsHttpContext.Current.Mode is equal to Unpublished
when the page loads from by own save button control.

When I click the 'Save' from the defaultconsole.ascx then the
CmsHttpContext.Current.Mode is in Update mode. So I either need to set the
CmsHttpContext.Current.Mode = to Update (which is readonly - so I don't know
how to do that) or I need to find out how I can get my own code to run when
the 'Save' within the defaultconsole.ascx is clicked.

Any ideas/help would be greatly appreciated.
--
James Coleman
Technical Director
AGENCY.COM [Chicago]


"Stefan [MSFT]" wrote:

> Hi James,
>
> are you in update when clicking this button?
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> Check out the new book as well: Advanced MCMS development:
> http://tinyurl.com/8ugwj
> ----------------------
>
>
> "James Coleman" <JamesColeman@discussions.microsoft.com> wrote in message
> news:F4E524F7-81D1-4A79-BAF4-25EBE6BF7EFC@microsoft.com...
>
>
>

Stefan [MSFT]

2006-03-21, 8:03 am

Hi James,

the correct way to do this is to implement a workflow event.
Here e.Context will be in Update mode.

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
Check out the new book as well: Advanced MCMS development:
http://tinyurl.com/8ugwj
----------------------


"James Coleman" <JamesColeman@discussions.microsoft.com> wrote in message
news:6A03160E-A221-4489-8972-57DF301E2608@microsoft.com...[vbcol=seagreen]
> Okay, it looks like the CmsHttpContext.Current.Mode is equal to
> Unpublished
> when the page loads from by own save button control.
>
> When I click the 'Save' from the defaultconsole.ascx then the
> CmsHttpContext.Current.Mode is in Update mode. So I either need to set
> the
> CmsHttpContext.Current.Mode = to Update (which is readonly - so I don't
> know
> how to do that) or I need to find out how I can get my own code to run
> when
> the 'Save' within the defaultconsole.ascx is clicked.
>
> Any ideas/help would be greatly appreciated.
> --
> James Coleman
> Technical Director
> AGENCY.COM [Chicago]
>
>
> "Stefan [MSFT]" wrote:
>


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com