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

Advanced RadWindow Problem

1 Answer 64 Views
Window
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 13 Oct 2008, 08:13 PM
I have a user control that opens a Radwindow in modal mode with a call back function that updates a content area on the control.  Works great.  But when I have more than one instance of the control on a single page, not so good because the java script methods get duplicated. It's an Address control so I need to have more than one instance on a page. 
Let me give what I tried to do, but only leads to a javascript error:
Rather than have the sript coded on the control in markup, I add the script dynamically at page load as follows:

 

if (Parent.Page.ClientScript.IsClientScriptBlockRegistered(AddressScriptName))

 

Parent.Page.ClientScript.RegisterClientScriptBlock(

this.GetType(), AddressScriptName, MakeScript());

 

m_rwAddressLookups.ClientCallBackFunction =

"CallBackFromAddressFunction" + AddressScriptName;

 

m_btnAdressLookup.Attributes.Add(

"onclick", "return ShowAddressLookupDialog" + AddressScriptName + "();");

 

 

private string AddressScriptName{

 

 

get { return "AddressScript" + this.ClientID; }

 

}

 

private string MakeScript()

 

{

 

return @"<script type='text/javascript'>

 

function ShowAddressLookupDialog"

 

+ AddressScriptName + @"()

 

{

var manager = $find('<%=m_rwmAddressLookups.ClientID %>');

manager.open(null, 'm_rwAddressLookups');

return false;

}

function CallBackFromAddressFunction"

 

+ AddressScriptName + @"(radWindow, returnValue)

 

{

var oArea = document.getElementById('<%=m_tbAddressId.ClientID %>');

if (returnValue)

{

oArea.innerText = returnValue.toString();

oArea.onchange();

}

}

</script>"

 

;

 

}
WHen I click the address lookup button the onclick event complains Object Expected on bolded function:

 

<

 

input type="submit" name="ctl00$ContentPlaceHolder1$m_contactAddressEdit$m_btnAdressLookup" value="Lookup Address" onclick="return ShowAddressLookupDialogAddressScriptctl00_ContentPlaceHolder1_m_contactAddressEdit();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentPlaceHolder1$m_contactAddressEdit$m_btnAdressLookup&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, false))" id="ctl00_ContentPlaceHolder1_m_contactAddressEdit_m_btnAdressLookup" class="FormButton" />

Appears that it does not find the client id qualified script function.

Any ideas?

 

1 Answer, 1 is accepted

Sort by
0
Tervel
Telerik team
answered on 16 Oct 2008, 12:36 PM
Hi Mark,

Your general approach looks correct - you try to add a unique suffix to the function so that a "different" instance of a function, configured in a different manner is called from each instance of the Address control.

That said, there is a mistake in the way you construct the function itself. Please note that the function is not on your aspx page. This means that the string you are building is not parsed by ASP.NET. This means that code such as var manager = $find('<%=m_rwmAddressLookups.ClientID %>');  will not be parsed and resolved on the server - rather it will be sent to the client-side unprocessed.

Please make sure you break the function string to parts and insert all relevant ID's yourself, e.g.

"var manager = $find('" + m_rwmAddressLookups.ClientID + "');"



Best wishes,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Window
Asked by
Mark
Top achievements
Rank 1
Answers by
Tervel
Telerik team
Share this question
or