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

Access FormTemplate controls from javascript when using UpdatePanel

3 Answers 173 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ruth Dahan
Top achievements
Rank 1
Ruth Dahan asked on 15 Mar 2009, 09:55 PM
Hi,
I am using grid with FormTemplate popup for edit or update row and i need to access the FormTemplate controls from javascript code.
I found a way to do that using he forums and documetations and it is working good. the problem is when i add update panel to my page in order to avoid postbacks, i get nulls while accessing my controls on javascript.

This is how i implement finding the controls:

in the code behind:

  protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
            { 
                GridEditFormItem editFormItem = (GridEditFormItem) e.Item; 
                RadComboBox cmbRoles = editFormItem.FindControl("RoleCombo"as RadComboBox; 
               
                if (cmbRoles != null
                { 
 
                    usersGrid.Controls.Add( 
                        new LiteralControl("<script type='text/javascript'>window['RolesComboId'] = '" + 
                                           cmbRoles.ClientID + 
                                           "';</script>")); 
                }               
                        
        } 

and on javascript:
function SetRoleVisibility(item) {           
 
            var cmbRoles = $find(window['RolesComboId']);  
        } 

When the SetRoleVisibility is fired cmbRoles should hold the RadComboBox. it does when not using update panel, but once i use one, the $find method returns null.

Can you please advice?

Thanks,
Ruth


3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Mar 2009, 07:38 AM
Hi,

One way to obtain the client-side instances of the combobox is using the tlrkComboBoxes array holding all the comboboxes on the page.


Accessing the combo on the client-side when it resides in a grid/formview/etc.

Try the same using an Ajax panel. Let me know of  any further issues.

Thanks,
Princy

0
Ruth Dahan
Top achievements
Rank 1
answered on 16 Mar 2009, 08:28 PM
Thanks for your reply,
i tried using the tlrkComboBoxes using the phrase:
 var input = document.getElementById(tlrkComboBoxes[0].InputID);
i got this exception in the javascript: 'tlrkComboBoxes' is undefined

am i doing something wrong?
0
Ruth Dahan
Top achievements
Rank 1
answered on 23 Mar 2009, 06:42 AM
Hi,
I solved the problem.
i implemented the ItemCreated event the following way:
if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
            { 
                GridEditFormItem editFormItem = (GridEditFormItem) e.Item; 
                 
                RadComboBox cmbRoles = editFormItem.FindControl("RoleCombo") as RadComboBox; 
                StringBuilder scriptBuilder = new StringBuilder(); 
 
                if (cmbRoles != null) 
                { 
                    scriptBuilder.AppendFormat("var cmbRolesClientID = '{0}';", cmbRoles.ClientID);                     
                    
                } 
 
                if (scriptBuilder != null && scriptBuilder.ToString() != "") 
                { 
                    ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "EditFormScript", scriptBuilder.ToString(), true); 
                } 
            }             

and used it on the client side this way:
  var cmbRoles = $find(cmbRolesClientID); 

BTW, i used the same way for all kind of controls, no just comboBoxes.

Thanks,
Ruth.
Tags
Grid
Asked by
Ruth Dahan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ruth Dahan
Top achievements
Rank 1
Share this question
or