onfocus problem

4 posts, 1 answers
  1. Gal
    Gal avatar
    48 posts
    Member since:
    Apr 2009

    Posted 04 Jul 2010 Link to this post

    I have a grid with a combo box in a template column and a date-time column all rows in the grid are in edit mode so in order to display additional info i need to add an on-focus event to trigger the additional data display.

    but it fails to trigger the event !! in on click it works fine ?
    here is my code :
    C#
        protected void RadGridTaskAssinging_ItemDataBound(object sender, GridItemEventArgs e)
        {
            for (int i = 0; i < RadGridTaskAssinging.PageSize; i++)
            {
                RadGridTaskAssinging.EditIndexes.Add(i);
            }
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                GridEditableItem edititem = (GridEditableItem)e.Item;
                RadDatePicker dPicker = (RadDatePicker)edititem["New_REMINDER_DATE_TIME"].Controls[0];
                dPicker.Width = Unit.Pixel(150);
                dPicker.Attributes.Add("onfocus", "ClickMe(" + edititem.GetDataKeyValue("S_ORDER_NUM") + "," + edititem.GetDataKeyValue("ACTIVE_NO") + ");");

                RadComboBox RadComboBoxUser = edititem.FindControl("RadComboBoxUser") as RadComboBox;
                RadComboBoxUser.Attributes.Add("onfocus", "ClickMe(" + edititem.GetDataKeyValue("S_ORDER_NUM") + "," + edititem.GetDataKeyValue("ACTIVE_NO") + ");");
            }
        }

    ASPX CODE
                <telerik:GridDateTimeColumn DataType="System.DateTime"
                                            DataField="New_REMINDER_DATE_TIME"
                                            HeaderText="Internal End Date"
                                            CurrentFilterFunction="EqualTo"
                                            AutoPostBackOnFilter="true"
                                            SortExpression="New_REMINDER_DATE_TIME"
                                            UniqueName="New_REMINDER_DATE_TIME"
                                            FilterControlWidth="150px"
                                            ReadOnly="False"
                                            PickerType="DateTimePicker">
                    <ItemStyle Wrap="False"/>                                          
                    <HeaderStyle Width="190px" />
                </telerik:GridDateTimeColumn>
                <telerik:GridTemplateColumn DataField="T_User.USER_NAME"
                                        HeaderText="Employee"
                                        GroupByExpression="T_User.USER_NAME"  
                                        SortExpression="T_User.USER_NAME"
                                        UniqueName="USER_NAME"
                                        FilterControlWidth="80px">
                                        <ItemTemplate>
                                            <%#DataBinder.Eval(Container.DataItem, "T_User.USER_NAME")%>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadComboBox ID="RadComboBoxUser"
                                                                runat="server"
                                                                ShowDropDownOnTextboxClick="false"
                                                                MarkFirstMatch="true"
                                                                AppendDataBoundItems="True"
                                                                Width="110px"
                                                                DataSourceID="LinqDataSourceUser"
                                                                DataTextField="USER_NAME"
                                                                DataValueField="USER_CODE"
                                                                SelectedValue='<%# Bind("USER_CODE")%>'>
                                            </telerik:RadComboBox>  
                                            <script type="text/javascript">
                                                function ClickMe(Order, Active) {
                                                    var inputOrder = document.getElementById("<%= input_S_ORDER_NUM.ClientID%>");
                                                    var inputActive = document.getElementById("<%= input_ACTIVE_NO.ClientID%>");
                                                    inputOrder.value = Order;
                                                    inputActive.value = Active;
                                                    var button = document.getElementById("<%= ButtonUpdateDetailes.ClientID%>");
                                                    button.disabled = false;
                                                    button.focus();
                                                    button.click();
                                                }                                                  
                                                </script>                                    
                                        </EditItemTemplate>
                    <ItemStyle Wrap="False" />                                          
                    <HeaderStyle Width="120px" />                                    
                </telerik:GridTemplateColumn>

    <asp:ImageButton ID="ButtonUpdateDetalies" runat="server" Enabled="false"
        ImageUrl="~/Images/Empty.png" Visible="true" />

    I found this post but it doesnt enable me to send parameters to the Javascript !!

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 07 Jul 2010 Link to this post

    Hi Gal,

    The RadComboBox control exposes a client-side focus event through its AJAX component API:

    <telerik:RadComboBox OnClientFocus="comboFocus">

    The event handler now exposes the client RadComboBox object as well as the Sys.EventArgs-inheriting event arguments object:

    function comboFocus(sender, args)
    {
        //sender is the RadComboBox AJAX component
        //args is the Sys.EventArgs-descending event arguments object
    }

    As for the date picker, try adding the focus event handler to the DateInput component of the picker, not to the picker itself:

    From:

    dPicker.Attributes.Add("onfocus", "ClickMe(" + edititem.GetDataKeyValue("S_ORDER_NUM") + "," + edititem.GetDataKeyValue("ACTIVE_NO") + ");");

    To:

    dPicker.DateInput.Attributes.Add("onfocus", "ClickMe(" + edititem.GetDataKeyValue("S_ORDER_NUM") + "," + edititem.GetDataKeyValue("ACTIVE_NO") + ");");


    Veli
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gal
    Gal avatar
    48 posts
    Member since:
    Apr 2009

    Posted 07 Jul 2010 Link to this post

    Hi Veli

    Thanks for your prompt response.
    As I said I found this post Its about the same as your response but it doesnt enable me to send parameters to the Javascript is there a walk around it ?
  5. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 08 Jul 2010 Link to this post

    Hi Gal,

    You can register an expando attribute to your combos from the server side:

    ScriptManager.RegisterExpandoAttribute(Page, RadComboBoxUser.ClientID, "ACTIVE_NO", editItem.GetDataKeyValue("ACTIVE_NO").ToString(), true)
     
    ScriptManager.RegisterExpandoAttribute(Page, RadComboBoxUser.ClientID, "S_ORDER_NUM", editItem.GetDataKeyValue("S_ORDER_NUM").ToString(), true)

    You call use this code in the ItemDataBound event where you register focus event handlers for the rest of your inputs. Now, with this setup, the OnClientSelectdIndexChanged event cant be used to get the expando attribute values:

    function comboFocus(sender, args)
    {
        var ACTIVE_NO = sender.get_element().ACTIVE_NO;
        var S_ORDER_NUM = sender.get_element().S_ORDER_NUM;
    }


    Regards,
    Veli
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top