Hi Everyone
I am having trouble with a RequiredField Validator for a ComboBox in Edit Form.
This is the scenario:
I have a grid with 3 columns:
1 TemplateColumn with a ComboBox as its EditItemTemplate
2 GridNumericColumns
I’ve placed OnBlur and OnFocus events on the two NumericColumnEditors.
I’ve Placed a Compare Field Validator for the comboBox
I’ve also disabled the ComboBox when it is in the Edit form.
Now, this works fine when I am in the Insert Form but when I hit the edit command I get this error:
htmlfile: Can't move focus to the control because it is invisible, not enabled, or of a type that does not accept the focus.
This is the JSCode:
var
oldValue;
function
Focus(sender, eventArgs)
{
oldValue = sender.get_value();
}
function
Blur (sender, eventArgs)
{
if
( sender.get_value() < 0)
{
radalert(
'El valor no puede ser negativo'
,200,100,
'Alerta'
);
sender.set_value(oldValue);
}
}
Markup:
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"LINEA"
HeaderText
=
"Linea ISA"
AllowFiltering
=
"False"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"LIN"
runat
=
"server"
Width
=
"80px"
>
<%# DataBinder.Eval(Container.DataItem, "LINEA")%>
</
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
DataTextField
=
"EQUIPO"
DataValueField
=
"EQUIPO"
EnableLoadOnDemand
=
"True"
ID
=
"RadCmbBx_Linea"
runat
=
"server"
MarkFirstMatch
=
"True"
OnSelectedIndexChanged
=
"RadCmbBx_Linea_SelectedIndexChanged"
AutoPostBack
=
"true"
>
</
telerik:RadComboBox
>
<
asp:CompareValidator
ValueToCompare
=
"Select..."
Operator
=
"NotEqual"
ControlToValidate
=
"RadCmbBx_Linea"
ErrorMessage
=
"You must select a city!"
runat
=
"server"
ID
=
"Comparevalidator1"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridNumericColumn
DataField
=
"ENERGIA_ACTIVA_HOY"
UniqueName
=
"ENERGIA_ACTIVA_HOY"
HeaderText
=
"Energia Hoy"
/>
<
telerik:GridNumericColumn
DataField
=
"ENERGIA_REACTIVA_HOY"
UniqueName
=
"ENERGIA_REACTIVA_HOY"
HeaderText
=
"Energia Hoy ReActiva"
/>
</
Columns
>
CodeBehind:
protected
void
RgridLineasISA_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && (e.Item.IsInEditMode))
{
RadComboBox comboLinea = e.Item.FindControl(
"RadCmbBx_Linea"
)
as
RadComboBox;
comboLinea.DataSource =
new
OES.Business.Equipo().ListLineasISA();
comboLinea.DataBind();
comboLinea.Items.Insert(0,
new
RadComboBoxItem(
"Select..."
));
if
((e.Item
as
GridEditableItem).IsInEditMode && (e.Item
as
GridEditableItem).IsDataBound && e.Item.ItemIndex != -1)
{
comboLinea.SelectedValue = ((OES_LineasISA)e.Item.DataItem).LINEA.ToString();
comboLinea.Enabled =
false
;
}
}
protected
void
RgridLineasISA_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && (e.Item.IsInEditMode))
{
GridNumericColumnEditor editorEnerActHoy = (GridNumericColumnEditor)e.Item.EditManager.GetColumnEditor(
"ENERGIA_ACTIVA_HOY"
);
editorEnerActHoy.NumericTextBox.ClientEvents.OnBlur =
"Blur"
;
editorEnerActHoy.NumericTextBox.ClientEvents.OnFocus =
"Focus"
;
GridNumericColumnEditor editorEnerReactHoy = (GridNumericColumnEditor)e.Item.EditManager.GetColumnEditor(
"ENERGIA_REACTIVA_HOY"
);
editorEnerReactHoy.NumericTextBox.ClientEvents.OnBlur =
"Blur"
;
editorEnerReactHoy.NumericTextBox.ClientEvents.OnFocus =
"Focus"
;
}
}
The exception is due to the CompareValidator, if I remove it then it works, but I need it in order to validate the ComboBox selected item.
How can I get rid of this execption?
Thanks!
Miguel