Geeks With Blogs

About Me:
I am a Female SharePoint Developer (a platinum unicorn). I have been working with SharePoint since I attended the Portal University in 2005. I hold a BA in Computer Science from the University of Missouri - Kansas City. I love playing Rockband, organizing user group meetings, working with code, attending events as a speaker or organizer, and having bizarre conversations about geek things with cool people. If you have any comments or questions fill out the contact form and I will try my best to help.

The Guide of a MOSSLover Becky Isserman's Blog

I was using the infamous InputFormTextbox, which is the SharePoint Rich Textbox.  I had full html turned on and rich text, so that users could get the full experience in my webpart.  I added a normal InputFormRequiredValidator and did some tests thinking yeah this is working fine.  The client comes back with an issue and tells me it’s not firing.  So I start stepping into the code and realize there is always a <DIV></DIV> tag.  I understand why it would add these tags for styling purposes, but why add the tags right off the bat?  Why not remove the tags after editing?  It gets even better after editing it adds a &nbsp; tag between the div tags after you erase all the text on editing.  So this obviously will not work with a RequiredFieldValidator of any type, because it has text in the background.  I tried creating CustomValidator fields just for the Rich Text items, but this is no good due to the fact that the boxes working with the RequireFieldValidator are client side and run before the new validation objects.  At this point I decided to just throw in CustomValidator objects for all validation, but that did not work fully due to the fact that CheckboxList does not work with normal validators (apparently InputFormCheckboxListValidator is the only one out there that I know about without writing a custom item).  So in the end I created a label and used the function for the server side custom validation.  I also realize that I had to use some regex and a string replace to dump all html the Rich Textbox was adding and all non-breaking spaces.  I threw in the new function with a check on the label being visible and the Page.IsValid option for server side validation checks.  Two days later it works 100% after a battery of tests.  So essentially  here is a summary:

  • Don’t use RequiredFieldValdator or InputFormRequiredFieldValidator with Rich Text Box options set on InputFormTextbox
  • Don’t mix CustomValidator with RequiredFieldValidator, even if you use the client side scripting it will not work at the same time as RequiredFieldValidator
  • You can’t use InputFormCheckboxList or CheckBoxList with any type of RequiredFieldValidator or CustomValidator, so you have to use your own custom functions or InputFormCheckboxListValidator.  Also, you can’t use InputFormCheckboxListValidator with CustomValidator, because it will not run at the same time as the CustomValidator
  • When running CustomValidator use Regex to remove any html tags and use a string replace to remove any non breaking spaces (since it’s adding extras in the background).

Hopefully someone out there finds this useful and saves them the time and hassle I had to deal with this week.  Have a good weekend guys.

Posted on Friday, March 20, 2009 1:36 PM | Back to top

Comments on this post: RequiredFieldValidator and InputFormTextBox not Friends…

# re: RequiredFieldValidator and InputFormTextBox not Friends…
Requesting Gravatar...
saw this solution... seems to work for me:
Left by Jay on Sep 10, 2013 1:17 PM

Your comment:
 (will show your gravatar)

Copyright © MOSSLover | Powered by: