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

Calling a javasvript routine from ajax panel OnAjaxRequest server event

2 Answers 82 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mick
Top achievements
Rank 1
Mick asked on 20 Aug 2008, 08:14 AM
Hi

I am having trouble calling a javscript routine from inside the ajax panel server event.

i have an ajax panel which wraps severel controls on the page so that when the server events fire, they all fire through ajax and not postback.
One button in particular needs to do some database processing and then call a javsacript routine that will open a new window.

I have tried the following methods inside the button click routine.

string strBuildUp = "<script type=\"text/javascript\">";
strBuildUp +=
" PaymentGateway('" + OrderId.ToString() +"')</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "paymentgateway", strBuildup);

I also tried
Page.Response.Write(strBuildUp);

and
Page.ClientScript.RegisterStartupScript(this.GetType(), "paymentgateway", " PaymentGateway('" + OrderId.ToString() + "')");

Then I tried to simplify the call with
Page.ClientScript.RegisterStartupScript(this.GetType(), "paymentgateway", "alert('hello'");
and
Page.Response.Write("alert('hello')");

if I remove the ajax panel then these will work fine!! (I like ajax I dont want to remove it)

None of the above worked for me I even replace registerstartupscript with register clientscriptblock (just in case).

I know that I can resolve this by creating an edit box on the page with no value, then creating a timer function that waits for a value to be added to the text box and then fires the javascript event from the javascript timer event.
On the server OnAjaxRequest event i simply put a value in the box and it all will happen.

But i was hoping for something a bit more tidier than that.
Does anyone know how i can achieve this without doing my suggested fudge?

2 Answers, 1 is accepted

Sort by
0
Accepted
Missing User
answered on 21 Aug 2008, 11:02 AM
Hi Mick ,

 You need to use ScriptManager instead

ScriptManager.RegisterStartupScript(.....)

Please, take a look at this blog post

Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Mick
Top achievements
Rank 1
answered on 21 Aug 2008, 11:37 AM
Cooking.

Cheers Lads, I new there would be a better way.
Tags
Ajax
Asked by
Mick
Top achievements
Rank 1
Answers by
Missing User
Mick
Top achievements
Rank 1
Share this question
or