November Happy Hour will be moved to Thursday December 5th.

How to do a Validation function to compare two custom properties in CMS Page?

Vote:
 

I’m using two Custom properties in a page.

One is a dropdownlist control and the other is a listbox.

I want to do a validation like If the Item selected from dropdown is matching with any selected item of the List box, then I need to show a message in the screen.

Please let us know your ideas.

Thanks.

#75253
Sep 23, 2013 18:20
Vote:
 

Hi,

I have done the following coding:

        public override void ApplyEditChanges()
        {
            try
            {
                ValidateSignPost()
                base.SetValue(strSelectedValue);
            }
            catch
            {
            }
        }
        public void ValidateSignPost()
        {

            List<ListItem> LstTest = new List<ListItem>();
            if (CurrentPage["HideSignPost"] != null &&
                    (CurrentPage["SignPost1"] != null))
            {
                LstTest = lbSignPost.Items.OfType<ListItem>().Where(a => a.Selected).ToList();
                if (LstTest.Any(li => li.Value == (CurrentPage["SignPost1"].ToString())))
                {
                    AlertAndClose();
                }
            }
        }

        protected void AlertAndClose()
        {
            this.Page.Response.Write(@"<script language='javascript'>alert('Sign Post and Hide Sign Post Values should not be the same.');</script>");
        }

With this code when I click on Save and Publish, I'm able to see an alert message but after closing the alert box I'm seeing that the page is published.

Is there any way that we can stop loading the page and to stay back on the Edit panel itself?

Thanks.

#75287
Sep 24, 2013 12:17
Vote:
 

Instead of returning script fragment try to add validation error to the collection:

protected void AlertAndClose()
{
    base.AddErrorValidator("Sign Post and Hide Sign Post Values should not be the same.");
}

    

#75289
Sep 24, 2013 12:36
Vote:
 

Thanks Valdis.

Your suggestion is working fine for me.

Thanks again.

#75354
Sep 25, 2013 19:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.