Hi all!
I am developing a Required Field Validator for a RadCombobox. The RadCombobox appears when I am modifying an item of a RadGrid, so when the CreateColumnEditor event fires.
My problem is: when I add a new item to my table, there a re no problem, while when I am editing ad existing item the value of the RadComboBox is not taken, so it gives a database exception of violation of integrity contraints.
Here there is the most significative part of my class.
When debugging I can see that the value of the radcomboboxes are wrong, even if the right item is selected.
The validation is done clientside with a javascript, because the RequiredFieldValidator wasn't working (could you please explain me why it wan't? It is in the commented code).
public class ComboEditor : GridDropDownListColumnEditor
{
private RadComboBox combo;
private String _datafield;
private bool _mandatory;
private bool _enableChange;
private Unit _width;
//private RequiredFieldValidator _reqValidator;
private CustomValidator _reqValidator;
public ComboEditor(GridDropDownColumn owner, bool mandatory, String datafield, bool enableChange, Unit width)
: base(owner)
{
this._datafield = datafield;
this._mandatory = mandatory;
this._enableChange = enableChange;
this._width = width;
}
public RadComboBox ComboControl
{
get
return base.ComboBoxControl;
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override int SelectedIndex
{
get
return base.SelectedIndex;
set
base.SelectedIndex = value;
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string SelectedValue
{
get
return base.SelectedValue;
set
base.SelectedValue = value;
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string SelectedText
{
get
return base.SelectedText;
set
base.SelectedText = value;
}
protected override void LoadControlsFromContainer()
{
this.combo = this.ContainerControl.Controls[0] as RadComboBox;
}
protected override void AddControlsToContainer()
{
HtmlGenericControl divCombo = new HtmlGenericControl("DIV");
divCombo.Attributes.Add("style", "padding-bottom: 3px;");
if (this.ContainerControl.Parent != null)
{
foreach (GridTableRow row in this.ContainerControl.Parent.Parent.Controls)
(row.Controls[0] as GridEditFormItem.EditFormTableCell).VerticalAlign = VerticalAlign.Top;
}
this.combo.NoWrap = false;
this.combo.MarkFirstMatch = true;
this.combo.AllowCustomText = false;
this.combo.Skin = "WebBlue";
this.combo.CausesValidation = true;
this.combo.Width = this._width;
this.combo.ToolTip = "Select " + this._datafield + "...";
this.combo.ID = "cmb" + this._datafield.Replace(" ", "");
divCombo.Controls.Add(this.combo);
this.ContainerControl.Controls.Add(divCombo);
if (this._mandatory)
{
this._reqValidator = new CustomValidator();
this._reqValidator.ID = "req" + this._datafield.Replace(" ", "");
this._reqValidator.ErrorMessage = " This field is required.";
this._reqValidator.ControlToValidate = this.combo.ID;
this._reqValidator.ClientValidationFunction = "ValidateComboBox";
this._reqValidator.EnableClientScript = true;
this.ContainerControl.Controls.Add(this._reqValidator);
/*this._reqValidator = new RequiredFieldValidator();
this._reqValidator.ID = "pippo";
this._reqValidator.ErrorMessage = "This field is required.";
this._reqValidator.ControlToValidate = this.combo.ID;
this._reqValidator.InitialValue = "";
this.ContainerControl.Controls.Add(this._reqValidator); */
}
}
protected override void CreateControls()
{
base.CreateControls();
base.ControlsCreated = true;
this.combo = base.ComboBoxControl;
}
}
I am developing a Required Field Validator for a RadCombobox. The RadCombobox appears when I am modifying an item of a RadGrid, so when the CreateColumnEditor event fires.
My problem is: when I add a new item to my table, there a re no problem, while when I am editing ad existing item the value of the RadComboBox is not taken, so it gives a database exception of violation of integrity contraints.
Here there is the most significative part of my class.
When debugging I can see that the value of the radcomboboxes are wrong, even if the right item is selected.
The validation is done clientside with a javascript, because the RequiredFieldValidator wasn't working (could you please explain me why it wan't? It is in the commented code).
public class ComboEditor : GridDropDownListColumnEditor
{
private RadComboBox combo;
private String _datafield;
private bool _mandatory;
private bool _enableChange;
private Unit _width;
//private RequiredFieldValidator _reqValidator;
private CustomValidator _reqValidator;
public ComboEditor(GridDropDownColumn owner, bool mandatory, String datafield, bool enableChange, Unit width)
: base(owner)
{
this._datafield = datafield;
this._mandatory = mandatory;
this._enableChange = enableChange;
this._width = width;
}
public RadComboBox ComboControl
{
get
return base.ComboBoxControl;
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override int SelectedIndex
{
get
return base.SelectedIndex;
set
base.SelectedIndex = value;
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string SelectedValue
{
get
return base.SelectedValue;
set
base.SelectedValue = value;
}
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override string SelectedText
{
get
return base.SelectedText;
set
base.SelectedText = value;
}
protected override void LoadControlsFromContainer()
{
this.combo = this.ContainerControl.Controls[0] as RadComboBox;
}
protected override void AddControlsToContainer()
{
HtmlGenericControl divCombo = new HtmlGenericControl("DIV");
divCombo.Attributes.Add("style", "padding-bottom: 3px;");
if (this.ContainerControl.Parent != null)
{
foreach (GridTableRow row in this.ContainerControl.Parent.Parent.Controls)
(row.Controls[0] as GridEditFormItem.EditFormTableCell).VerticalAlign = VerticalAlign.Top;
}
this.combo.NoWrap = false;
this.combo.MarkFirstMatch = true;
this.combo.AllowCustomText = false;
this.combo.Skin = "WebBlue";
this.combo.CausesValidation = true;
this.combo.Width = this._width;
this.combo.ToolTip = "Select " + this._datafield + "...";
this.combo.ID = "cmb" + this._datafield.Replace(" ", "");
divCombo.Controls.Add(this.combo);
this.ContainerControl.Controls.Add(divCombo);
if (this._mandatory)
{
this._reqValidator = new CustomValidator();
this._reqValidator.ID = "req" + this._datafield.Replace(" ", "");
this._reqValidator.ErrorMessage = " This field is required.";
this._reqValidator.ControlToValidate = this.combo.ID;
this._reqValidator.ClientValidationFunction = "ValidateComboBox";
this._reqValidator.EnableClientScript = true;
this.ContainerControl.Controls.Add(this._reqValidator);
/*this._reqValidator = new RequiredFieldValidator();
this._reqValidator.ID = "pippo";
this._reqValidator.ErrorMessage = "This field is required.";
this._reqValidator.ControlToValidate = this.combo.ID;
this._reqValidator.InitialValue = "";
this.ContainerControl.Controls.Add(this._reqValidator); */
}
}
protected override void CreateControls()
{
base.CreateControls();
base.ControlsCreated = true;
this.combo = base.ComboBoxControl;
}
}