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

Loosing focus in RadGrid combo selected index change.

13 Answers 319 Views
Grid
This is a migrated thread and some comments may be shown as answers.
siva
Top achievements
Rank 1
siva asked on 26 Jul 2009, 11:23 AM
Hi ,
I am using a RadGrid and i have a RadCombo in one of the column.  That combo has  external call back.

When the radcombo box triggers the selected index changed event of server side.  There in the code behind based on condition
I want to change the focus to either the same combo or next control in the grid. How ever as the page refreshes the i am loosing the focus.  I want IsPostback to be "True" because i have some condition to check in serverside.  And the focus should move to the next control in the grid.

Please tell me how i can achieve this?
Code in server side:
if condition()
{
((RadComboBox)currentEditItem["AmendmentNumber"].FindControl("ddlAmendmentNos")).Focus()
}
else
{

currentEditItem["AmendmentPurpose"].Focus();
((RadTextBox)currentEditItem["AmendmentPurpose"].FindControl("txtPurpose")).Focus();
}

RadCombo Settings:
<rad:GridTemplateColumn UniqueName="AmendmentNumber" DataField="Number" HeaderText="Bylaw #" ItemStyle-Width="10%"><ItemTemplate> <rad:RadComboBox Height="200px" ID="ddlAmendmentNos" MaxLength="10" runat="server" ToolTip="Enter Bylaw Number"AllowCustomText="true" MarkFirstMatch="false" ShowToggleImage="False" SkinsPath="~/RadControls/ComboBox/Skins"Skin="LIComboBoxSkin" ShowMoreResultsBox="true" EnableLoadOnDemand="True" ExternalCallBackPage="AmendmentNosDropDownBox.aspx"OnClientFocus="OnClientFocus" Text='<%# Eval("Number")%>' DataTextField="Number" OnSelectedIndexChanged="ddlAmendmentNos_SelectedIndexChanged"DataValueField="ID" AutoPostBack="true" ShowDropDownOnTextboxClick="false"></rad:RadComboBox></ItemTemplate></rad:GridTemplateColumn>

Regards
Siva Kumar KB

13 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 29 Jul 2009, 11:38 AM
Hello siva,

Basically, you can use the selected index changed event handler for the combo, to get a reference to it, and then to its naming container, which would be the edit form. From there, you can access all the elements in the edit form, and set the focus to them accordingly.
I hope this suggestion get you started properly.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Poornima S
Top achievements
Rank 1
answered on 30 Jul 2009, 08:45 AM
Thanks Yavor for the reply.

I tried implementing the suggestion provided by you. But it is not working for me.

I got the reference to the textbox to which i want to set the focus in the selected index changed event of the rad comb box as follows,
    ControlToFocus = ((RadTextBox)currentEditItem["AmendmentPurpose"].FindControl("txtPurpose"))

and then to the naming container as,
    ControlToFocus.NamingContainer.

In the PreRender event of the page, i tried to set the focus to the textbox as
    ControlToFocus.NamingContainer.FindControl("txtPurpose").Focus();

Please help!!!

Thanks
Poornima
0
Mira
Telerik team
answered on 05 Aug 2009, 09:40 AM
Hello Poornima S,

I attached a sample project with the desired functionality.
This is the part of the code where focus is being transferred to the next control:
protected void RadComboBox1_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        RadComboBox comboBox = (RadComboBox)sender; 
        GridEditableItem current = (GridEditableItem)comboBox.NamingContainer; 
        current.FindControl("RadComboBox2").Focus(); 
 
    } 

I hope I managed to help you solve your problem. Please contact us if you need further assistance.

Sincerely yours,
Mira
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Stacy
Top achievements
Rank 1
answered on 04 Feb 2011, 03:46 PM
I have this code below...

<MasterTableView    DataKeyNames="Key">
<Columns>
        <wasp:GridTemplateControl 
            UniqueName="TemplateOrganizationUnitLevelId"        >
            <ItemTemplate >
                   <wasp:ComboBoxControl 
                        ID="OrganizationUnitLevelId" 
                        AutoPostback="True"
                        runat="server" 
                        ReadOnly='<%# ReadOnly %>'
                        meta:resourcekey="OrganizationUnitLevelId"
                        onselectedindexchanged="OrganizationUnitLevelId_SelectedIndexChanged"
                        ondatabinding="OrganizationUnitLevelId_DataBinding"
                       Value='<%# Bind("OrganizationUnitHierarchyId") %>'
                        LabelValue='<%# Bind("OrganizationUnitLevelId") %>' 
                        >
                   </wasp:ComboBoxControl>
            </ItemTemplate>
        </wasp:GridTemplateControl>
        <wasp:GridTemplateControl
            UniqueName="Template">
            <ItemTemplate>
                <wasp:DateControl 
                    ID="OrganizationUnitHierarchyStartDate" 
                    Text="Start Date" 
                    runat="server" 
                    LabelValue='<%# Bind("OrganizationUnitLevelId") %>' 
                    meta:resourcekey="OrganizationUnitHierarchyStartDate" 
                    OnSelectedDateChanged="OrganizationUnitHierarchyStartDate_SelectedDateChanged"  
                    Value='<%# Bind("OrganizationUnitHierarchyStartDate") %>'  ReadOnly='<%# ReadOnly %>'  />
            </ItemTemplate>
        </wasp:GridTemplateControl>
</Columns>
  
</MasterTableView>

On the SelectedIndexChanged method of the combo box, i am trying to set focus to the date control.  I have tried using these four methods:

1.  ((ComboBoxControl)sender).BindingContainer.FindControl("OrganizationUnitHierarchyStartDate").Focus();
  
2.  ((ComboBoxControl)sender).NamingContainer.FindControl("OrganizationUnitHierarchyStartDate").Focus();
  
3.  Page.SetFocus(((ComboBoxControl)sender).BindingContainer.FindControl("OrganizationUnitHierarchyStartDate"));
  
4.  ComboBoxControl comboBox = (ComboBoxControl)sender;
     GridEditableItem current = (GridEditableItem)comboBox.NamingContainer;
     current.FindControl("OrganizationUnitHierarchyStartDate").Focus();

The result is I always lose focus.  This grid is a control that is part of another ascx.  Any ideas?
0
Mira
Telerik team
answered on 07 Feb 2011, 11:57 AM
Hello Stacy,

Have you ajaxified your pages?
In case you have, I recommend that you use the FocusControl method of the RadAjaxControl.

I hope this helps.

Best wishes,
Mira
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
Stacy
Top achievements
Rank 1
answered on 07 Feb 2011, 01:52 PM
The main control(ascx) has ajax, this second control(ascx, which gets included in the first ascx) does not have ajax and since it's included in the first, it wont know about the RadAjaxManager.
0
Mira
Telerik team
answered on 09 Feb 2011, 12:21 PM
Hello Stacy,

Please use the GetCurrent method of the RadAjaxManager in order to get the AJAX manager instance.
You can examine the RadAjax and WebUserControls help topic for additional information.

I hope this helps.

Regards,
Mira
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
Stacy
Top achievements
Rank 1
answered on 09 Feb 2011, 02:21 PM

I have tried using this:

RadAjaxManager temp = RadAjaxManager.GetCurrent(Page);
temp.FocusControl(((ComboBoxControl)sender).BindingContainer.FindControl("OrganizationUnitHierarchyStartDate"));

But it does not focus on the control.
0
Mira
Telerik team
answered on 14 Feb 2011, 11:28 AM
Hello Stacy,

Please use the following code in order to implement the desired functionality:
void combo_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox comboBox = (RadComboBox)o;
    GridEditableItem current = (GridEditableItem)comboBox.NamingContainer;
    RadAjaxManager.GetCurrent(Page).FocusControl(current.FindControl("RadComboBox2").ClientID +"_Input");
}

You can examine the Setting Focus demo for additional information.

Greetings,
Mira
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
Stacy
Top achievements
Rank 1
answered on 14 Feb 2011, 02:16 PM
That has no effect either. 
0
Mira
Telerik team
answered on 15 Feb 2011, 01:57 PM
Hello Stacy,

I tried to replicate the issue which you described, but to no avail.
Attached to this message, you will find the code which I used for testing.

Please, take a look at it and let me know if there are any differences at your end, which I may be leaving out.

Kind regards,
Mira
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
Stacy
Top achievements
Rank 1
answered on 15 Feb 2011, 02:21 PM
As i've said throughout my postings, i'm using a control within a control.  I do not see this in the code you have attached.

I have my ascx and within it, i reference another ascx (ie.  <uc2:OrganizationUnitControl id="blah"... />

When the selectedIndexChanged event fires for the comboboxes in "OrganizationUnitControl", i cannot get them to keep focus or move focus to the next input item.
0
Mira
Telerik team
answered on 21 Feb 2011, 09:25 AM
Hello Stacy,

Are the both comboxes in the OrganizationUnitControl control?
If yes, please use the following code:
void combo1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
{
    RadComboBox comboBox = (RadComboBox)o;
    GridEditableItem current = (GridEditableItem)comboBox.NamingContainer;
    RadAjaxManager.GetCurrent(Page).FocusControl(current.FindControl("RadComboBox2").ClientID + "_Input");
}
If they are not, please provide more information on the structure of your page.

I hope this helps.

Greetings,
Mira
the Telerik team
Tags
Grid
Asked by
siva
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Poornima S
Top achievements
Rank 1
Mira
Telerik team
Stacy
Top achievements
Rank 1
Share this question
or