| Tony Collings 2006-06-26, 7:25 am |
| We have a custom XML Placeholder written, which I've extended the
functionality of.
I'm trying to extend it further but running into problems.
You can see a screenshot of the end result here :
http://www.northamptonshire.gov.uk/img/screenshot.jpg
Basically I'm trying to multiple validation on the "Review Date"
Currently validation rules exist for
1. Must have a date
2. Must be in correct format.
I'm trying to extend it, such that in addition there is the following
3. Date not exceed 6 months from now.
4. If they enter a date that's already passed it warns.
Basically I've written a custom validator, and set it to args.IsValid =
false, so it always fails, It works OnSavingContent, however when I do
"Save As" from the editor menu it's seems to completely by-pass my
validation. Using "Save" it's fine, but not "Save As".
Any ideas ?
Here's the class:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml;
using System.Xml.Xsl;
using Microsoft.ApplicationBlocks.Data;
using Microsoft.ContentManagement.Publishing;
using Microsoft.ContentManagement.Publishing.Extensions.Placeholders;
using Microsoft.ContentManagement.WebControls.Design;
using Microsoft.ContentManagement.WebControls;
using System.Globalization;
using NCC_HelperClasses;
namespace NCC_WebControlLibrary
{
/// <summary>
/// Summary description for DropDownPlaceholderControl.
/// </summary>
[ SupportedPlaceholderDefinitionType( typeof(XmlPlaceholderDefinition)
) ]
public class Placeholder_MetaData : BasePlaceholderControl
{
// constructor for Placeholder_Links
// defines drop-down list visible at authoring time
public Placeholder_MetaData()
{
}
#region members and properties
// member variables to store authoring and presentation controls
// private Image imgPresentation;
// private DropDownList ddlAuthoringControl;
private CmsHttpContext context;
// private BaseModeContainer thisPresentationContainer;
private BaseModeContainer thisAuthoringContainer;
private Table tbl;
private TableRow tr;
private TableCell tc;
private TextBox txtName = new TextBox();
private TextBox txtJobTitle = new TextBox();
private TextBox txtSection = new TextBox();
private TextBox txtOrganisation = new TextBox();
private TextBox txtEmail = new TextBox();
private TextBox txtReviewDate = new TextBox();
private RequiredFieldValidator reqDate = new
RequiredFieldValidator();
// Validates Date, checks if it is passed, or within one month. ]
// TCollings Added 26/06/2006
private CustomValidator cusElapsedDate = new CustomValidator();
// END
private RequiredFieldValidator reqRank = new
RequiredFieldValidator(); //TCollings Added 21/04/2006
private CustomValidator cusLGCL = new CustomValidator();
private CustomValidator cusLGIL = new CustomValidator();
private RegularExpressionValidator regDate = new
RegularExpressionValidator();
private Literal litPopupLGCL = new Literal();
private Literal litPopupLGIL = new Literal();
private CheckBox chkUseMyDetails = new CheckBox();
private HtmlInputHidden hidCurrentAuthor = new HtmlInputHidden();
private HtmlInputHidden hidPreviousAuthor = new HtmlInputHidden();
private TextBox txtLGCL = new TextBox();
private TextBox txtGCL = new TextBox();
private TextBox txtLGSL = new TextBox();
private TextBox txtLGIL = new TextBox();
private HtmlInputHidden hidLGCL = new HtmlInputHidden();
private HtmlInputHidden hidGCL = new HtmlInputHidden();
private HtmlInputHidden hidLGSL = new HtmlInputHidden();
private HtmlInputHidden hidLGIL = new HtmlInputHidden();
private DateTime dtReview;
private DropDownList ddlPageRank = new DropDownList(); // Added
01092005 TCollings (Mondosearch)
private TextBox txtPageRank = new TextBox(); // Added 01092005
TCollings (Mondosearch)
private TextBox txtRankWords = new TextBox(); // Added 09092005
TCollings (Mondosearch)
private const string AUTHOR = "Author";
private const string LGCL = "LGCL";
private const string GCL = "GCL";
private const string LGSL = "LGSL";
private const string LGIL = "LGIL";
private const string REVIEWDATE = "REVIEWDATE";
private const string PAGERANK = "PAGERANK"; // Added 01092005
TCollings (Mondosearch)
private const string RANKWORDS = "RANKWORDS"; // Added 09092005
TCollings (Mondosearch)
private int intLGCL = -1;
private int intGCL = -1;
private int intLGSL = -1;
private int intLGIL = -1;
private string strReviewDate = "";
private string strPageRank = "";
//CmsHttpContext.Current.Posting.CustomProperties["PAGERANK"].Value.ToString();
private string strRankWords = "";
/// <summary>
/// Message to display if no rank words added
/// </summary>
private string _RequiredRankMessage;
public string RequiredRankMessage
{
get
{
return _RequiredRankMessage;
}
set
{
_RequiredRankMessage = value;
}
}
/// <summary>
/// Message to display if no date entered
/// </summary>
private string _RequiredErrorMessage;
public string RequiredErrorMessage
{
get
{
return _RequiredErrorMessage;
}
set
{
_RequiredErrorMessage = value;
}
}
/// <summary>
/// Message to display if date is in the incorrect format
/// </summary>
private string _RegularErrorMessage;
public string RegularErrorMessage
{
get
{
return _RegularErrorMessage;
}
set
{
_RegularErrorMessage = value;
}
}
/// <summary>
/// Message to display if LGCL is not entered
/// </summary>
private string _LGCLErrorMessage;
public string LGCLErrorMessage
{
get
{
return _LGCLErrorMessage;
}
set
{
_LGCLErrorMessage = value;
}
}
/// <summary>
/// Message to display if LGIL is not entered
/// </summary>
private string _LGILErrorMessage;
public string LGILErrorMessage
{
get
{
return _LGILErrorMessage;
}
set
{
_LGILErrorMessage = value;
}
}
/// <summary>
/// Message to display if date has elapsed.
/// </summary>
private string _ElapsedDateErrorMessage;
public string ElapsedDateErrorMessage
{
get
{
return _ElapsedDateErrorMessage;
}
set
{
_ElapsedDateErrorMessage = value;
}
}
/// <summary>
/// Date Expression
/// </summary>
private string _Expression;
public string Expression
{
get
{
return _Expression;
}
set
{
_Expression = value;
}
}
#endregion
#region private methods
private void GetContext()
{
if(context == null)
{
context = CmsHttpContext.Current;
}
}
private Table GetControls()
{
tbl = new Table();
tbl.CssClass = "metadataControl";
AddTableHeader();
AddTableEmptyRow();
AddTableLabelRow("Author Details:");
chkUseMyDetails.ID = "chkUseMyDetails";
hidPreviousAuthor.ID = "hidPreviousAuthor";
AddCheckBox(chkUseMyDetails, hidPreviousAuthor);
AddAuthorItem("Name:", txtName);
AddAuthorItem("Job Title:", txtJobTitle);
AddAuthorItem("Section/Dept:", txtSection);
AddAuthorItem("Organisation:", txtOrganisation);
AddAuthorItem("email:", txtEmail);
AddPageRank("Page Rank:", ddlPageRank); // Added by TCollings
01092005 (Mondosearch)
AddRankWords("Ranking Words:", txtRankWords); // Added by TCollings
09092005 (Mondosearch)
AddTableEmptyRow();
AddTableLabelRow("Category:");
txtRankWords.ID = "txtRankWords";
txtLGCL.ID = "txtLGCL";
txtGCL.ID = "txtGCL";
txtLGSL.ID = "txtLGSL";
txtLGIL.ID = "txtLGIL";
hidLGCL.ID = "hidLGCL";
hidGCL.ID = "hidGCL";
hidLGSL.ID = "hidLGSL";
hidLGIL.ID = "hidLGIL";
AddCategoryItem("LGCL:", txtLGCL, hidLGCL, "lgcl");
AddCategoryItem("GCL:", txtGCL, hidGCL, "");
AddCategoryItem("LGSL:", txtLGSL, hidLGSL, "");
AddCategoryItem("LGIL:", txtLGIL, hidLGIL, "lgil");
AddReviewDate();
AddTableEmptyRow();
return tbl;
}
private void AddCheckBox(CheckBox chk, HtmlInputHidden hid)
{
GetContext();
if(context.Posting.CustomProperties[AUTHOR].Value != null
&& context.Posting.CustomProperties[AUTHOR].Value != ""
&& context.Posting.CustomProperties[AUTHOR].Value !=
context.User.ClientAccountName)
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.ColumnSpan = 2;
tc.Controls.Add(chk);
tc.Controls.Add(new LiteralControl("Replace author details with my
details."));
tc.Controls.Add(hid);
tr.Controls.Add(tc);
}
}
private void AddTableHeader()
{
tr = new TableRow();
tbl.Controls.Add(tr);
TableHeaderCell th = new TableHeaderCell();
th.ColumnSpan = 2;
th.Controls.Add(new LiteralControl("Page Metadata:"));
tr.Controls.Add(th);
}
private void AddTableLabelRow(string label)
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.ColumnSpan = 2;
tc.CssClass = "metadataControlLabelRow";
tc.Controls.Add(new LiteralControl(label));
tr.Controls.Add(tc);
}
private void AddTableEmptyRow()
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.ColumnSpan = 2;
tc.Controls.Add(new LiteralControl(" "));
tr.Controls.Add(tc);
}
private void AddAuthorItem(string label, TextBox txt)
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.CssClass = "metadataControlLabel";
tr.Controls.Add(tc);
Literal lit = new Literal();
lit.Text = label;
tc.Controls.Add(lit);
tc = new TableCell();
tr.Controls.Add(tc);
txt.CssClass = "metadataControlReadonlyTextBox";
txt.ReadOnly = true;
tc.Controls.Add(txt);
}
// Added to enable Keyword search for Mondosoft
//TCollings 09092005
private void AddRankWords(string label, TextBox txtRankWords)
{
try
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tr.Controls.Add(tc);
tc = new TableCell();
tc.CssClass = "metadataControlDescription";
tc.Text = "Enter any keywords here seperated by commas
(,)<br/>Keywords are used by Search Engines to 'Rank' this page in
search results";
tr.Controls.Add(tc);
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.CssClass="metadataControlLabel";
tc.Text = "Keywords";
tc.VerticalAlign = VerticalAlign.Top;
tr.Controls.Add(tc);
tc = new TableCell();
tr.Controls.Add(tc);
txtRankWords.CssClass = "metadataControlReadonlyTextBox";
txtRankWords.TextMode = TextBoxMode.MultiLine;
txtRankWords.Rows = 2;
txtRankWords.Text =
CmsHttpContext.Current.Posting.CustomProperties[RANKWORDS].Value;
tc.Controls.Add(txtRankWords);
}
catch
{
}
}
// Added to enable Manual Page Ranking for Mondosoft
// TCollings 01092005
private void AddPageRank(string label, DropDownList ddlPageRank)
{
try
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.CssClass="metadataControlLabel";
tr.Controls.Add(tc);
//Visible ONLY to cms-admin
if(CmsHttpContext.Current.User.ServerAccountName ==
"WinNT://PERTH/cms-admin")
{
tc.Text = "Mondosearch Page Rank";
}
else
{
tc.Text = "";
}
tc = new TableCell();
tr.Controls.Add(tc);
ddlPageRank.CssClass = "metadataControlReadonlyTextBox";
ddlPageRank.Items.Add("");
ddlPageRank.Items.Add("+2");
ddlPageRank.Items.Add("-2");
ddlPageRank.ID = "ddlPageRank";
int whatIndex = 0;
string whatRank =
CmsHttpContext.Current.Posting.CustomProperties["PAGERANK"].Value.ToString();
switch (whatRank)
{
case "":
whatIndex = 0;
break;
case "+2":
whatIndex = 1;
break;
case "-2":
whatIndex = 2;
break;
default:
whatIndex = 0;
break;
}
//Visible ONLY to cms-admin
if(CmsHttpContext.Current.User.ServerAccountName ==
"WinNT://PERTH/cms-admin")
{
ddlPageRank.Visible = true;
}
else
{
ddlPageRank.Visible = false;
}
ddlPageRank.SelectedIndex = whatIndex;
tc.Controls.Add(ddlPageRank);
}
catch
{
}
}
// END
private void AddCategoryItem(string label, TextBox description,
HtmlInputHidden hid, string changeOption)
{
tr = new TableRow();
tbl.Controls.Add(tr);
tc = new TableCell();
tc.CssClass = "metadataControlLabel";
tr.Controls.Add(tc);
Literal lit = new Literal();
lit.Text = label;
tc.Controls.Add(lit);
switch(changeOption)
{
case "lgcl":
tc.Controls.Add(litPopupLGCL);
break;
case "lgil":
tc.Controls.Add(litPopupLGIL);
break;
}
tc = new TableCell();
tr.Controls.Add(tc);
description.CssClass = "metadataControlReadonlyTextBox";
description.ReadOnly = true;
tc.Controls.Add(description);
tc.Controls.Add(hid);
}
private void AddReviewDate()
{
tr = new TableRow();
TableRow trErrors = new TableRow();
TableCell tcErrors = new TableCell();
tbl.Controls.Add(tr);
tbl.Controls.Add(trErrors);
trErrors.Controls.Add(new TableCell());
trErrors.Controls.Add(tcErrors);
tc = new TableCell();
tc.CssClass = "metadataControlLabel";
tr.Controls.Add(tc);
Literal lit = new Literal();
lit.Text = "Review Date:";
tc.Controls.Add(lit);
tc = new TableCell();
tr.Controls.Add(tc);
tc.Controls.Add(new LiteralControl("dd/mm/yyyy "));
txtReviewDate.ID = "txtReviewDate";
txtReviewDate.MaxLength = 10;
tc.Controls.Add(txtReviewDate);
tc.Controls.Add(new LiteralControl(" "));
reqDate.ID = "reqDate";
reqDate.ControlToValidate = "txtReviewDate";
reqDate.EnableClientScript = true;
reqDate.Display = ValidatorDisplay.Dynamic;
reqDate.ErrorMessage = this.RequiredErrorMessage;
tcErrors.Controls.Add(reqDate);
// Code to add validation for Review Date ( Checks if it's correct )
cusElapsedDate.ID = "elapseddate";
cusElapsedDate.ControlToValidate = "txtReviewDate";
// Server validation
cusElapsedDate.ServerValidate +=new
ServerValidateEventHandler(cusElapsedDat
e_ServerValidate);
cusElapsedDate.Display = ValidatorDisplay.Dynamic;
cusElapsedDate.ErrorMessage = this.ElapsedDateErrorMessage;
tcErrors.Controls.Add(cusElapsedDate);
regDate.ID = "regDate";
regDate.ValidationExpression = _Expression;
regDate.ControlToValidate = "txtReviewDate";
regDate.EnableClientScript = true;
regDate.Display = ValidatorDisplay.Dynamic;
regDate.ErrorMessage = this.RegularErrorMessage;
tcErrors.Controls.Add(regDate);
cusLGCL.ID = "lgcl";
cusLGCL.ControlToValidate = "txtLGCL";
cusLGCL.EnableClientScript = true;
cusLGCL.ClientValidationFunction = "validLGCL";
cusLGCL.ServerValidate +=new
ServerValidateEventHandler(cusLGCL_Serve
rValidate);
cusLGCL.Display = ValidatorDisplay.Dynamic;
cusLGCL.ErrorMessage = this.LGCLErrorMessage;
tcErrors.Controls.Add(cusLGCL);
cusLGIL.ID = "lgil";
cusLGIL.ControlToValidate = "txtLGIL";
cusLGIL.EnableClientScript = true;
cusLGIL.ClientValidationFunction = "validLGIL";
cusLGIL.ServerValidate +=new
ServerValidateEventHandler(cusLGIL_Serve
rValidate);
cusLGIL.Display = ValidatorDisplay.Dynamic;
cusLGIL.ErrorMessage = this.LGILErrorMessage;
tcErrors.Controls.Add(cusLGIL);
reqRank.ID = "reqRank";
reqRank.ControlToValidate = "txtRankWords";
reqRank.EnableClientScript = true;
reqRank.Display = ValidatorDisplay.Dynamic;
reqRank.ErrorMessage = this.RequiredRankMessage;
tcErrors.Controls.Add(reqRank);
}
void cusLGCL_ServerValidate(object source, ServerValidateEventArgs
args)
{
if(hidLGCL.Value == "" || hidLGCL.Value == "-1")
{
args.IsValid = false;
}
}
void cusLGIL_ServerValidate(object source, ServerValidateEventArgs
args)
{
if(hidLGIL.Value == "" || hidLGIL.Value == "-1")
{
args.IsValid = false;
}
}
// Custom Validation for Review Date ( checking for Elaped )
void cusElapsedDate_ServerValidate(object source,
ServerValidateEventArgs args)
{
args.IsValid = false;
// DateTime date = Convert.ToDateTime(txtReviewDate.Text);
//
// if(date < System.DateTime.Now )
// {
// args.IsValid = false;
// }
}
private void LoadData()
{
GetContext();
Posting p = context.Posting;
DataSet ds;
string strAuthor = null;
if(p.CustomProperties[AUTHOR] != null &&
p.CustomProperties[AUTHOR].Value != "")
{
strAuthor = p.CustomProperties[AUTHOR].Value;
hidPreviousAuthor.Value = strAuthor;
}
else
{
strAuthor = context.User.ClientAccountName;
}
ds = SqlHelper.ExecuteDataset(Connection.ConnectionString(),
"u_Authors_Select_ByAccount", strAuthor);
if(ds.Tables[0].Rows.Count > 0)
{
txtName.Text = ds.Tables[0].Rows[0]["name"].ToString();
txtJobTitle.Text = ds.Tables[0].Rows[0]["jobTitle"].ToString();
txtSection.Text = ds.Tables[0].Rows[0]["section"].ToString();
txtOrganisation.Text =
ds.Tables[0].Rows[0]["organisation"].ToString();
txtEmail.Text = ds.Tables[0].Rows[0]["email"].ToString();
}
if(p.CustomProperties[LGCL] != null &&
p.CustomProperties[LGCL].Value != "")
{
intLGCL = Int32.Parse(p.CustomProperties[LGCL].Value);
}
if(p.CustomProperties[GCL] != null && p.CustomProperties[GCL].Value
!= "")
{
intGCL = Int32.Parse(p.CustomProperties[GCL].Value);
}
if(p.CustomProperties[LGSL] != null &&
p.CustomProperties[LGSL].Value != "")
{
intLGSL = Int32.Parse(p.CustomProperties[LGSL].Value);
}
if(p.CustomProperties[LGIL] != null &&
p.CustomProperties[LGIL].Value != "")
{
intLGIL = Int32.Parse(p.CustomProperties[LGIL].Value);
}
if(p.CustomProperties[REVIEWDATE] != null &&
p.CustomProperties[REVIEWDATE].Value != "")
{
string[] arr = p.CustomProperties[REVIEWDATE].Value.Split('-');
strReviewDate = arr[2] + "/" + arr[1] + "/" + arr[0];
}
try
{
if(p.CustomProperties[PAGERANK] != null &&
p.CustomProperties[PAGERANK].Value != "")
{
strPageRank = p.CustomProperties[PAGERANK].Value;
}
}
catch
{
}
try
{
if(p.CustomProperties[RANKWORDS] != null &&
p.CustomProperties[RANKWORDS].Value != "")
{
strRankWords = p.CustomProperties[RANKWORDS].Value;
}
}
catch
{
}
ds = SqlHelper.ExecuteDataset(Connection.ConnectionString(),
"u_Metadata_Select", intLGCL, intGCL, intLGSL, intLGIL);
txtLGCL.Text = ds.Tables[0].Rows[0][0].ToString();
txtGCL.Text = ds.Tables[0].Rows[0][1].ToString();
txtLGSL.Text = ds.Tables[0].Rows[0][2].ToString();
txtLGIL.Text = ds.Tables[0].Rows[0][3].ToString();
txtReviewDate.Text = strReviewDate;
hidLGCL.Value = intLGCL.ToString();
hidGCL.Value = intGCL.ToString();
hidLGSL.Value = intLGSL.ToString();
hidLGIL.Value = intLGIL.ToString();
//vReturnValue = window.showModalDialog(sURL [, vArguments] [,
sFeatures])
litPopupLGCL.Text = "<a onclick=\"java script:" +
TemplateHelper.ShowModalScript(ResolveUrl("~/popups/LGCL.aspx"),
"currentItem=' + eval(getItemValue('" + hidLGCL.ClientID + "')) +
'&gcl=' + eval(getItemValue('" + hidGCL.ClientID + "')) + '&lgsl=' +
eval(getItemValue('" + hidLGSL.ClientID + "')) + '",
800,
1000,
txtLGCL.ClientID + "|" + hidLGCL.ClientID + "|" + txtGCL.ClientID +
"|" + hidGCL.ClientID + "|" + txtLGSL.ClientID + "|" +
hidLGSL.ClientID,
true) +
"\" style=\"text-decoration:underline;cursor:hand;\">Change</a>";
litPopupLGIL.Text = "<a onclick=\"java script:" +
TemplateHelper.ShowModalScript(ResolveUrl("~/popups/LGIL.aspx"),
"currentItem=' + eval(getItemValue('" + hidLGIL.ClientID + "')) +
'",
600,
800,
txtLGIL.ClientID + "|" + hidLGIL.ClientID,
true) +
"\" style=\"text-decoration:underline;cursor:hand;\">Change</a>";
//register custom validation scripts
string cusVal;
cusVal = "<script language=\"javascript\">" +
"function validLGCL(sender, args)" +
"{" +
"var control = document.getElementById('" + hidLGCL.UniqueID +
"');"+
"if(control) {"+
"if(control.value != '' && control.value != '-1'){"+
"args.IsValid = true;" +
"} else {"+
"args.IsValid = false;" +
"}} else {"+
"args.IsValid = false;" +
"}"+
"return;"+
"}"+
"</script>";
Page.RegisterStartupScript("lgcl", cusVal);
cusVal = "<script language=\"javascript\">" +
"function validLGIL(sender, args)" +
"{" +
"var control = document.getElementById('" + hidLGIL.UniqueID +
"');"+
"if(control) {"+
"if(control.value != '' && control.value != '-1'){"+
"args.IsValid = true;" +
"} else {"+
"args.IsValid = false;" +
"}} else {"+
"args.IsValid = false;" +
"}"+
"return;"+
"}"+
"</script>";
Page.RegisterStartupScript("lgil", cusVal);
}
private void saveDescription(object sender, WebAuthorPostingEventArgs
e)
{
}
#endregion
#region overrides
// add the authoring control to the collection
protected override void
CreateAuthoringChildControls(BaseModeCon
tainer authoringContainer)
{
this.thisAuthoringContainer = authoringContainer;
authoringContainer.Controls.Add(GetControls());
}
// define and add the presentation control to the collection
protected override void
CreatePresentationChildControls(BaseMode
Container
presentationContainer)
{
}
// load content into the authoring control by selecting list item
protected override void
LoadPlaceholderContentForAuthoring(Place
holderControlEventArgs e)
{
EnsureChildControls();
LoadData();
}
// load content into the presentation control as literal text
protected override void
LoadPlaceholderContentForPresentation(Pl
aceholderControlEventArgs e)
{
}
protected override void OnSavingContent
(PlaceholderControlSavingEventArgs e)
{
if (this.AuthoringChildControlsAreAvailable)
{
this.reqDate.Validate();
if (!this.reqDate.IsValid)
{
e.Cancel = true;
}
this.regDate.Validate();
if (!this.regDate.IsValid)
{
e.Cancel = true;
}
this.cusElapsedDate.Validate();
if (!this.cusElapsedDate.IsValid)
{
e.Cancel = true;
}
this.cusLGCL.Validate();
if (!this.cusLGCL.IsValid)
{
e.Cancel = true;
}
this.cusLGIL.Validate();
if (!this.cusLGIL.IsValid)
{
e.Cancel = true;
}
try
{
IFormatProvider culture = new CultureInfo("en-GB", true);
dtReview = DateTime.Parse(txtReviewDate.Text, culture);
}
catch
{
e.Cancel = true;
}
}
base.OnSavingContent(e);
}
// save the selected item from the drop-down list as XML
protected override void
SavePlaceholderContent(PlaceholderContro
lSaveEventArgs e)
{
EnsureChildControls();
GetContext();
Posting p = e.Posting;
if(!chkUseMyDetails.Checked && hidPreviousAuthor.Value != "")
{
p.CustomProperties[AUTHOR].Value = hidPreviousAuthor.Value;
}
else
{
p.CustomProperties[AUTHOR].Value = context.User.ClientAccountName;
}
p.CustomProperties[LGCL].Value = hidLGCL.Value;
p.CustomProperties[GCL].Value = hidGCL.Value;
p.CustomProperties[LGSL].Value = hidLGSL.Value;
p.CustomProperties[LGIL].Value = hidLGIL.Value;
p.CustomProperties[REVIEWDATE].Value =
dtReview.ToString("yyyy-MM-dd");
try
{
p.CustomProperties[PAGERANK].Value =
ddlPageRank.SelectedValue.ToString();
}
catch
{
}
try
{
p.CustomProperties[RANKWORDS].Value = txtRankWords.Text.ToString();
}
catch
{
}
try //dummy content, the custom properties do the business
{
((XmlPlaceholder)this.BoundPlaceholder).XmlAsString =
"<content></content>";
}
catch (Exception exp)
{
// Possible validation exceptions
// If you want, you can override it with your own custom exception
string newExceptionMessage = String.Format( "[{0} \"{1}\"] Error
saving placeholder contents: {2}", this.GetType().Name, this.ID,
exp.Message );
Exception overriddenException = new Exception(newExceptionMessage,
exp);
// raise new exception so the BasePlaceholderControl can handle it
throw overriddenException;
}
}
#endregion
}
}
|