EditForm ComboBox Focus

5 posts, 0 answers
  1. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 15 Dec 2010 Link to this post


    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

  2. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 16 Dec 2010 Link to this post

    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!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 17 Dec 2010 Link to this post

    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.
  5. Miguel
    Miguel avatar
    25 posts
    Member since:
    Dec 2010

    Posted 17 Dec 2010 Link to this post

    Is there anything else I can do for the CompareValidator?
  6. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 23 Dec 2010 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017