This is a migrated thread and some comments may be shown as answers.

EditForm ComboBox Focus

4 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Miguel
Top achievements
Rank 1
Miguel asked on 16 Dec 2010, 03:10 AM


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

4 Answers, 1 is accepted

Sort by
0
Miguel
Top achievements
Rank 1
answered on 16 Dec 2010, 11:04 PM
Hi guys, I really hope you can help me out!!! I have not been able to figure out what the problem is.

I appreciate your help!

Miguel!
0
Nikolay Rusev
Telerik team
answered on 17 Dec 2010, 02:05 PM
Hello Miguel,

I am afraid that I am not able to replicate the behavior locally. However I suspect that is caused due to CompareValidatior that is attempting to return focus to control which is disabled.

All the best,
Nikolay
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Miguel
Top achievements
Rank 1
answered on 17 Dec 2010, 03:44 PM
Is there anything else I can do for the CompareValidator?
0
Nikolay Rusev
Telerik team
answered on 23 Dec 2010, 10:28 AM
Hello Miguel,

I am not sure about your use case, but you should avoid setting focus on invisible/disabled controls.

Greetings,
Nikolay
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Miguel
Top achievements
Rank 1
Answers by
Miguel
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or