Pages

Search This Blog

Monday, May 9, 2011

Get “RichTextField” Control Value in SharePoint 2007

When building custom application pages in SharePoint you may need to put the BaseFieldControl objects for a SPListItem. If the application page is performing add or edit functions you will need to iterate through the Fields and get values from the BaseFieldControls. It works well for most of the BaseFieldControl but there’s some problem to get value from RichTextField.
Here is the right way to get value back from RichTextField control in SharePoint:


private string GetRichTextBoxControlValue(Control control)
        {
            string returnValue = string.Empty;

            foreach (System.Web.UI.Control ctrl in control.Controls)
            {
                if (ctrl is TemplateContainer)
                {
                    foreach (System.Web.UI.Control templateCtrl in ctrl.Controls)
                    {
                        if (templateCtrl is HtmlContainerControl)
                        {
                            foreach (System.Web.UI.Control hdnCtrl in templateCtrl.Controls)
                            {
                                if (hdnCtrl is HtmlInputHidden)
                                {
                                    returnValue = ((HtmlInputHidden)hdnCtrl).Value;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            return returnValue;
        }

No comments:

Post a Comment