Using ValidationGroup with Sharepoint EditorPart
I have written a Sharepoint 2007 web part which requires validation in both the User form, and the Admin form (EditorPart).
I am using InputFormRegularEdpressionValidator to do the validation like this:
tb = new TextBox();
tb.ID = "myID";
InputFormRegularExpressionValidator validTb = new
InputFormRegularExpressionValidator();
validTb.ControlToValidate = tb.ID;
validTb.ValidationExpression = myRegExp;
validTb.ValidationGroup = "AdminInput";
this.Controls.Add(tb);
this.Controls.Add(validTb);
I have defined two validation groups - one for the UserInput and the other for AdminInput. I defined a submit but开发者_如何学运维ton in the user form, and set this ValidationGroup to UserInput,
However, I can't figure out how to apply the ValidationGroup AdminInput to the Ok and Apply buttons in the Editor part, or otherwise validate these fields.
How does one trigger validtion of EditorPart fields on clicking Ok/Apply separately from validation of fields in the public facing web part?
In this case i would suggest use the solution provided in link below
How to set an error message from EditorPart when ApplyChanges returns false?
string _errorText;
public override bool ApplyChanges()
{
if (System.Text.RegularExpressions.Regex.IsMatch(validTb.Text, myRegExp))
{
//write you code here in case of valid input
return true;
}
else
{
_errorMessage = "Not A valid String";
return false;
}
}
protected override OnPreRender(EventArgs e)
{
if (!string.IsNullOrEmpty(_errorText))
{
this.Zone.ErrorText = _errorText;
}
base.OnPreRender(e);
}
精彩评论