Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello sir,
i have to redirect from current page to another page. e.g. i have one webservice method and it's work successfully but when any error is occurs then i have to redirect my custom error page.
my current page is City.aspx and my Error page is error.aspx
i used below code..

C#
[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static string InsertRequest(string bid
                                            , string cid
                                            , int bookqty
                                            , string rmk)
        {
            try
            {
                  //here is my insert code and it's working...         
            }
            catch (Exception ex)
            {
                HttpContext.Current.Session["errorMsg"] = ex.Message;
                HttpContext.Current.Response.Redirect("error.aspx?pagename=" + System.IO.Path.GetFileNameWithoutExtension(HttpContext.Current.Request.PhysicalPath), false);
                return "fail";
            }


i also use below code..
C#
HttpContext.Current.Server.Transfer("error.aspx?pagename=" + System.IO.Path.GetFileNameWithoutExtension(HttpContext.Current.Request.PhysicalPath));

But not working

i also use below code..

C#
HttpContext.Current.Response.Write("<script>");
HttpContext.Current.Response.Write("window.location='error.aspx?p=" + pageName + "'");
HttpContext.Current.Response.Write("</script>");


But not working....


please help...

thanks in advance..!!
Posted
Comments
Thanks7872 11-Mar-15 7:18am    
See this : http://forums.asp.net/post/5569241.aspx
F-ES Sitecore 11-Mar-15 7:40am    
It's not your browser that is accessing the code so your browser can't respond to a redirect request. You'll need to make whatever calls the code do the redirect, so post the code that actually calls the method.
Sinisa Hajnal 11-Mar-15 7:52am    
Your response.redirect seems fine - what error do you get (if any) - try putting try...catch around it (yes, I know you're already in a catch block, but this is for testing)
Surendra0x2 11-Mar-15 8:25am    
error: function () {
windows.location.href = "URL";
}
Use ajax error function

1 solution

You can't because you are not in a full postback. You need to return a value and then look for that value in JavaScript and then use window.location.href from javascript.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900