Dear Telerik Community,
Currently i am developing an dynamic field initializer where validation expressions are used. Those expressions are set dynamicly in de codebehind attached to a textbox for example. My problem lays in the option that i sometimes don't want to set the validation expression in the regexptextboxsetting for example. When i leave the validationexpression empty the textbox will validate but on the wrong way. It automaticly deletes the value of the textbox and gives an warning sign that it is not correct.
My question is, can i set the validationexpression empty so that no validation is set and that it wont validate the control? In the following code snippit you will see what i have done:
Maybe my thougts are wrong :-) so can somebody help me?
Kind regards,
Michiel Peeters
Currently i am developing an dynamic field initializer where validation expressions are used. Those expressions are set dynamicly in de codebehind attached to a textbox for example. My problem lays in the option that i sometimes don't want to set the validation expression in the regexptextboxsetting for example. When i leave the validationexpression empty the textbox will validate but on the wrong way. It automaticly deletes the value of the textbox and gives an warning sign that it is not correct.
My question is, can i set the validationexpression empty so that no validation is set and that it wont validate the control? In the following code snippit you will see what i have done:
/// <summary>
/// Generates the textual control.
/// </summary>
/// <param name="fieldDefinition">Fielddefinition that holds the data that needs to be set on the control.</param>
/// <returns>A textual control based on a textbox.</returns>
private
TextBox textualControl(ServiceObjectFieldDefinition fieldDefinition, RadInputManager inputManager)
{
string
controlId =
string
.Format(
"dynamicFieldControl-{0}"
, fieldDefinition.Id);
this
.dynamicFieldControlSequenceIds.Add(controlId);
RegExpTextBoxSetting textualValidationSetting =
new
RegExpTextBoxSetting();
textualValidationSetting.BehaviorID = controlId;
TextBox textualTextbox =
new
TextBox();
textualTextbox.ID = controlId;
if
(fieldDefinition.Mandatory)
textualValidationSetting.Validation.IsRequired =
true
;
if
(fieldDefinition.MaxLength !=
null
)
textualTextbox.MaxLength = Convert.ToInt32(fieldDefinition.MaxLength);
if
(!
string
.IsNullOrEmpty(fieldDefinition.DefaultValue))
textualTextbox.Text = fieldDefinition.DefaultValue;
if
(fieldDefinition.DefaultValueFixed)
textualTextbox.Enabled =
false
;
textualValidationSetting.ValidationExpression = fieldDefinition.MinLength !=
null
?
string
.Format(
"{{0},}"
, Convert.ToInt32(fieldDefinition.MinLength)) :
"{0,}"
;
TargetInput textualValidationInput =
new
TargetInput(controlId,
true
);
textualValidationSetting.TargetControls.Add(textualValidationInput);
inputManager.InputSettings.Add(textualValidationSetting);
this
.dynamicControls.Add(textualTextbox);
return
textualTextbox;
}
Maybe my thougts are wrong :-) so can somebody help me?
Kind regards,
Michiel Peeters