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

[Solved] radconfirm not working with Inject Script

6 Answers 368 Views
Window
This is a migrated thread and some comments may be shown as answers.
Emmet
Top achievements
Rank 1
Emmet asked on 07 Mar 2008, 11:16 AM

I have a usercontrol with the following hierarchy

Parent.master -> CreatePeople.master -> Details.aspx -> Details.ascx

In CreatePeople.master there is a RadWindowManager.

If in Details.ascx I add a button and put code in the OnClientClick event to open a radconfirm window it works fine.

However if I add another button and in its OnClick event use the InjectScript method to run the radconfirm window it fails with a javascript error 'undefined is null or not an object'. If I debug the javascript with firefox the code seems to be having trouble finding the window manager.

I've isolated this in a mini project which just contains the files mentioned. No Ajax managers or anything like that.

Any ideas?

Code Behind:

protected void button1_Click(object sender, EventArgs e)
{
InjectScript.Text =
"<script>confirmSaveDuplicatePerson()</script>";
}

Details.ascx

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function confirmSaveDuplicatePerson()
{
radconfirm('
Are you sure?',confirmSaveCallback,330,100,null,'Duplicate');
}

function confirmSaveCallback(arg)
{
radalert(arg);
}
</script>
</
telerik:RadCodeBlock>
<asp:Label ID="InjectScript" runat="server"></asp:Label>
<
asp:Button ID="button1" runat="server" Text="click me" OnClick="button1_Click" />
<
asp:Button ID="buttonClient" runat="server" Text="Client click" OnClientClick="confirmSaveDuplicatePerson(); return false;" />




 

 

6 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 11 Mar 2008, 11:21 AM
Hi Emmet,

Your site is an AJAXEnabledWebSite and despite of having no RadAjaxManager you have a ScriptManager and the page lifecycle is the lifecycle of an ajaxified page. This being said, the "Prometheus" controls as all ajax objects are rendered last on the page. That's why you need ensure that before the function's execution the RadWindowManager control is rendered on the page. To do this you should add a load handler and execute your function there as shown below:

 InjectScript.Text = "<script> Sys.Application.add_load(confirmSaveDuplicatePerson)</script>"



Greetings,
Svetlina
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Emmet
Top achievements
Rank 1
answered on 11 Mar 2008, 01:02 PM
That works for my sample project, Thanks.

However my actual project is a little more complicated. It has a RadAjaxManager on the CreatePeople.master page. On the Details page it has a button control that updates the Details.ascx. So in order to prevent refreshes I added the following code into Details.ascx.cs

protected void Page_Load(object sender, EventArgs e)
{
RadAjaxManager _mgr = FindAjaxManager(this.Parent);
Button _btn = FindButton(this.Parent);
_mgr.AjaxSettings.AddAjaxSetting(_btn,
this);
}

private Button FindButton(Control parent)
{
Button buttonDummy = (Button)parent.FindControl("dummyButton");

if (parent.Parent != null && buttonDummy == null)
{
    
return FindButton(parent.Parent);
}
else if (buttonDummy != null)
{
    return buttonDummy;
}

throw new Exception("Unable to locate peopleButtons in the parent control hierarchy.");
}

private RadAjaxManager FindAjaxManager(Control parent)
{

RadAjaxManager mgr = (RadAjaxManager)parent.FindControl("RadAjaxManager1");

if (parent.Parent != null && mgr == null)
{
    
return FindAjaxManager(parent.Parent);
}
else if (mgr != null)
{
    
return mgr;
}
throw new Exception("Unable to locate RadAjaxManager in the parent control hierarchy.");
}

Now the code you suggested doesn't work. I tried using the ResponseScripts collection in the AjaxManager but that doesn't seem to work either. 

protected void button1_Click(object sender, EventArgs e)
{
RadAjaxManager _mgr = FindAjaxManager(this.Parent);
_mgr.ResponseScripts.Add(
"Sys.Application.add_load(confirmSaveDuplicatePerson);");
}

Is there any work around for this situation.

Thanks

Emmet

0
Georgi Tunev
Telerik team
answered on 14 Mar 2008, 10:59 AM
Hi Emmet,

I am not quite sure about your exact setup, but I created a small sample that shows how to achieve the desired behavior. In the example I use the ResponceScipts collection of the ajax manager and everything is working as expected. Can you please check it and let me know if I am missing something?

If you still experience problems, please open a support ticket and send us a small sample project which shows your exact setup and the problem itself. We will check it and get back to you with solution right away.


Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
David O'Shuaghnessy
Top achievements
Rank 1
answered on 31 Mar 2008, 03:13 PM
Sorry for my delay in replying but I was moved onto another project for a while.

I have a solution, rather than using add_load if I use add_init it seems to work correctly

_mgr.ResponseScripts.Add(

"Sys.Application.add_init(confirmSaveDuplicatePerson);");

Thanks

Emmet

0
Georgi Tunev
Telerik team
answered on 01 Apr 2008, 10:08 AM
Hi David,

It is good to know that you solved the problem by yourself. I would only recommend to use add_load instead of add_init.
Basically when add_init is executed, the RadWindowManager is created. To be sure that the RadWindowManager will be fully loaded, it is better to use add_load that is called after the init phase.



Regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Bobby Davis
Top achievements
Rank 1
answered on 29 Apr 2008, 02:32 PM
Sorry Georgi your code just flat doesn't work.

David's init code is the only one that works in this case. So your suggestion to use add_load was completly wrong.

I really wish you guys could get a better handle on this stuff and quit leaving it to your clients to figure it out.

Thanks,
Tags
Window
Asked by
Emmet
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Emmet
Top achievements
Rank 1
Georgi Tunev
Telerik team
David O'Shuaghnessy
Top achievements
Rank 1
Bobby Davis
Top achievements
Rank 1
Share this question
or