fs
Guest
|
Posted:
Tue Jan 04, 2005 12:49 pm Post subject:
RE: CMS Placeholder Validation |
|
|
Hi Kele,
There are more than one way to do this, but depending on how complex your
validations are and how many fields you want to validate.
In my case, I once did a template with five fields that has date range
validations, and regular expression matchings. My approach is to create these
fields using normal asp.net controls and throw in a couple of asp.net
validation controls for each of them. These validations will fire
automatically on client-side lost focus and postback.
Then I also have a hidden placeholder, which I populate with an xml string
of the validated values of each field on postback. The validations work just
like a normal asp.net page, but we have to bind the validated xml string from
the hidden placeholder to whatever presentation we want in presentation mode.
This might be a step too many for a single field validation, thus
alternatively we can just write our validation codes in the onsubmitting
event handler. It looks something like this:
public void CmsPosting_Submitting(Object sender, ChangingEventArgs e)
{
Posting currentPosting = (Posting) e.Target;
HTMLPlaceholder validatePlaceholder;
validatePlaceholder = (HTMLPlaceholder)
currentPosting.Placeholders["myPlaceholder"];
if (validatePlaceholder != null) //this will skip validation codes for
other postings
{
bool isValid = false;
//validation code goes here
//example:
//try {
// if (int.Parse(validatePlaceholder.Text)) > 10) isValid = true;
// catch
// {}
if (!isValid) //validation failed
{
Exception customException = new Exception("Value must be integer
greater than 10!");
//get webauthor context and raise the error
WebAuthorContext webAuthCtx = WebAuthorContext.Current;
webAuthCtx.RaiseErrorEvent(new
WebAuthorErrorEventArgs("FailedSubmit", customException);
//cancels the submit
e.Cancel = true;
e.SuppressExceptionOnCancel = true;
}
}
}
Hope this helps...
"Kele" wrote:
| Quote: |
Is there any good way of being able to implement
Validation on a CMS Placeholder in the Template. eg.
Date Validation ie for Release Date Placeholder.
Are you able to use the validation controls against a
placeholder? If so how do you do this?
Thanks,
Kele.
|
|
|