|
Home > Archive > Microsoft Content Management Server > January 2005 > CMS Placeholder Validation
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 |
CMS Placeholder Validation
|
|
|
|
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.
| |
|
| 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:
>
> 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.
>
>
| |
| Stefan [MSFT] 2005-01-04, 7:47 am |
| Hi Kele,
please check this ready to use solution:
http://www.gotdotnet.com/Community/...4F-2CCA72FF4704
Cheers,
Stefan.
"Kele" <anonymous@discussions.microsoft.com> wrote in message
news:0c0101c4f221$8e96da30$a501280a@phx.gbl...
>
> 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.
>
|
|
|
|
|