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

Grid EditFormItem and lookup window

4 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 30 Jun 2008, 07:52 AM

Hi,
I have a grid which has an edit form template and on the template is a linkbutton which opens a RadWindow as a customer lookup. I can easily return the customer name and address picked by the user from this lookup window to the calling form using ClientCallbackFunction and I want to use the returned data to perform a client-side update a couple of  label controls in the calling grid's editform. The trouble is, I cannot find the label controls.

I have tried using the following principle:

<script ...>
function callBack(args)
{
 var labelToUpdate = $find("%<=lblCustomerName.clientID%>")
}
</script>

but of course I get a compile-time error stating the lblCustomerName does not exists. (lblCustomerName is a label in the editform template.)

How can I find the label control in the grid's editform so I can change the label's value from the ClientCallbackFunction?

The page is Ajax-ified using a RadAjaxManager.

Thanks,
Jonathan

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 02 Jul 2008, 08:21 AM
Hi Jonathan,

Thank you for contacting us. You can access controls in edit form when your grid is switching for editing i.e you can get reference for that label from your edit form OnItemCreated:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)  
{  
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
 {  
  string script = String.Format("lblCustomerNameID = '{0}';\n", e.Item.FindControl("lblCustomerName").ClientID);  
  ClientScript.RegisterClientScriptBlock(Page.GetType(), "mykey", script, true);  
 }  
and in lblCustomerNameID you will have the reference to that label's ClientID. On the client you will have
<script type="text/javascript">                  
 var lblCustomerNameID;                  
 function someFunction()  
 {  
  $get(lblCustomerNameID).innerHTML = "Some text in the grid";  
 }  
</script> 

I hope that helps.

Kind regards,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan
Top achievements
Rank 1
answered on 03 Jul 2008, 02:30 PM

Thanks Nikolay, works like a dream. I had to make a couple of small changes to make it work as the page with the grid has a master page and I found the statement:

var lblCustomerNameID;

had to go in the master page so that it was declared before the the client script block was written.

Many thanks for your help.

Regards,
Jonathan

0
Jonathan
Top achievements
Rank 1
answered on 03 Jul 2008, 11:14 PM
OK, I'm not quite home yet. The solution works great with RadAjaxManager EnableAJAX="false" and the script is written to the page.

But when EnableAJAX="true" then the script is not written. I'm fairly new to the rad ajax controls and don't quite know how to get around this.

Can you help?
Regards,
Jonathan
0
Jonathan
Top achievements
Rank 1
answered on 04 Jul 2008, 05:46 AM

Oops. I found the answer 2 minutes after posting the last question.

Using: 

RadAjaxManager1.ResponseScripts.Add(Script) 


solves the problem.

Thanks,
Jonathan

Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or