tags:

views:

336

answers:

3

I am using:

[ajax.ajaxmethod()]
public void fnName()

containing:

response.redirect("sample.aspx");

or:

server.transfer("sample.aspx");

both are not working... what is the solution?

in that block, I tried to call javascript function as

scriptmanager.registerstartupscript(page,gettype(),"sample","javascriptfunction()",true);

it's also not working..

A: 

You need to provide way more detail, but I'm going to wildly guess you expect your ajax request to become redirect the page? That'll never work - at best the ajax request itself will be redirected to your new content.

You need the ajax response to provide the URL you want to redirect to, and the front end to understand the format of that response (because it's just a string otherwise) and act upon it (e.g. document.location = foo). i.e. The redirect will have to happen on the client side.

Of course you could be askign something completely different.

annakata
+1  A: 

I don't know how you do this with ASP.NET AJAX, but in Ra-Ajax you would use something like this;

AjaxManager.Instance.WriterAtBack.Write("window.location='foo.aspx';");

My guess is that also ASP.NET AJAX have some sort of method to append JavaScript back in Ajax Callbacks like Ra-Ajax does and that you can use that to append a window.location redirect...

There is no other way to do that as I am aware of...

However for Ra-Ajax there's also a "shorthand" version for redirecting which can be found here; AjaxManager.Instance.Redirect

I would be surprised if not also ASP.NET AJAX have something similar...

Thomas Hansen
+1  A: 

I guess the problem is that you are trying to execute Server-Side code (C#) at the client side. As Thomas answered, the Javascript equivalent to response.redirect("foo.aspx") or server.transfer("foo.aspx") is window.location='foo.aspx'.

Jader Dias