Ajax method

I use:

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

      

contains:

response.redirect("sample.aspx");

      

or

server.transfer("sample.aspx");

      

both don't work ... what is the solution?

in this block, i tried to call the javascript function like

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

      

it doesn't work either.

0


source to share


3 answers


I don't know how you do it 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 ASP.NET AJAX has some way of adding JavaScript to Ajax Callbacks like Ra-Ajax, and that you can use that to add a redirect ....



There is no other way to do this as I know ...

However, for Ra-Ajax there is also a "shorthand" version for redirection, which can be found here; AjaxManager.Instance.Redirect

I would be surprised if ASP.NET AJAX didn't have anything like this ...

+1


source


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



+1


source


You need to provide more details, but I am guessing that you are expecting your ajax request to be redirected to the page? This will never work - at best, the ajax request itself will be redirected to your new content.

You need an ajax response to specify the url you want to redirect to and an interface to understand the format of that response (because it's just a string otherwise) and act on it (e.g. document.location = foo). those. the redirection must happen on the client side.

Of course, you could write something completely different.

0


source







All Articles