InputFormTextBox 非空验证

之前遇到的问题:

  <sharepoint:InputFormTextBox ID="UsernameTextBox" TextMode="MultiLine" runat="server" class="ms-input" RichTextMode="FullHtml" RichText="true" Title="Username" Rows="6" Width="300px" Height="100px"/>
<sharepoint:InputFormCustomValidator ID="UsernameCustomValidator" runat="server" Display="Dynamic" SetFocusOnError="true"
ControlToValidate
="UsernameTextBox"
ClientValidationFunction
="IsValidUsername"
ErrorMessage
="Your content must be at less 20 characters long (client-side validation)."
ValidateEmptyText
="true" />
<script language="javascript">
function IsValidUsername(source, args)
{
if (args.Value.length >= 20)
args.IsValid
= false;
else
args.IsValid
= true;
}
</script>

在没有设置RichText的时候, 可以验证, 但是设置RichText=True之后就无法验证了,是个怎么回事? 

为什么不使用RequiredFieldValdator 或者 InputFormRequiredFieldValidator不起验证作用?
因为RichText="true" 时,内容前后就会加上<div></div>,空内容时,值为<div>&nbsp;</div>。

所以在RichText="true"时,可行的验证方法如下:

function ValidateComments()
{
//retrieve the text from rich text editor.
var text = RTE_GetRichEditTextOnly("<%= rteComments.ClientID %>");
if (text != "")
{
return true;
}
else
{
alert('Please enter your comments.');

//set focus back to the rich text editor.
RTE_GiveEditorFocus("<%= rteComments.ClientID %>");
return false;
}
return true;
}

<SharePoint:InputFormTextBox ID="rteComments" runat="server" RichText="true" RichTextMode="Compatible" Rows="10" TextMode="MultiLine" CausesValidation="true" ></SharePoint:InputFormTextBox>

<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" OnClientClick="return ValidateComments()" CausesValidation="true" />





posted on 2012-03-27 11:20  向振文  阅读(605)  评论(0编辑  收藏  举报