Results 1 to 7 of 7

Thread: C# Equivalent Of Javascript's Location.replace() Function?

  1. #1
    Join Date
    Jun 2009
    Posts
    87

    C# Equivalent Of Javascript's Location.replace() Function?

    Hello to everyone. I had used many times Javascripts location.replace() function. This method is used to Redirect the Browser to the new page without adding that to the history. I want to know the code from which I will able to do that in the C#. If you have any server side code then give that details to me.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: C# Equivalent Of Javascript's Location.replace() Function?

    If you are using an asynchronous callback from the WebAsyncRefreshPanel, then you have to make use of the source code from below and then you will able to solve your problem. It will simply move your browser to the different page :
    Code:
    Response.Redirect("Redirection.aspx", true);

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: C# Equivalent Of Javascript's Location.replace() Function?

    You can use the HttpResponse.Redirect Method:
    The HttpResponse class implements two overloaded versions of the Redirect method.
    • The first overloaded method takes only one input parameter, which is the URL for the target location. This version is defined as follows:
      Code:
            public void Redirect(string url);
    • The second overloaded method takes two input parameters: the URL for the target location, and a boolean value that indicates whether to stop running the current page. This version is defined as follows:
      Code:
            public void Redirect(string url, bool endResponse);

    When you use the first overloaded version, the second overloaded version is called internally and is passed a boolean value of True for the second input parameter.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: C# Equivalent Of Javascript's Location.replace() Function?

    If you want to send your browser from the one page to the another page directly then you can simply make use of the function for that and solve your problem. You can pass that details to the URL either as a database key or a message string. You can use the session object also for that. If you are using the redirection for the one page by passing the ID on the Query string “True” then that will simply stop the current page. So, just make use of the code below:
    Code:
    Response.Redirect("one.aspx?id=45", true);

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: C# Equivalent Of Javascript's Location.replace() Function?

    Hey, I have got the code below from which you will able to get the solution for your Javascript's Location.replace() Function:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public partial start : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs ea)
        {
            if (Request.Browser["IsMobileDevice"] == "true")
            {
                Response.Redirect("firstPage.aspx");
            }
            else
            {
                Response.Redirect("secondPage.aspx");
            }
        }
    }

  6. #6
    Join Date
    Oct 2005
    Posts
    2,393

    Re: C# Equivalent Of Javascript's Location.replace() Function?

    Hello, I would simply suggest you to make use of the source code below and then you will able to solve your problem. If you make use of that then you will able to get the C# Equivalent Of Javascript's Location.replace() Function as below:
    Code:
    context.Response.Redirect(@"http://www.techarena.in");
    I have used it and it is working fine for me for redirecting the web page.

  7. #7
    Join Date
    May 2008
    Posts
    2,389

    Re: C# Equivalent Of Javascript's Location.replace() Function?

    If you are searching for the souce code for the redirection of the browser then you will able to force the browser to go to differnt page. It may be also possible to use the type below for redirection your page as in the Javascript.

    Code:
    LiteralControl literalcontrol = new LiteralControl("<script language='javascript'>window.location='second.aspx';</script>");
    this.WebAsyncRefreshPanel1.Controls.Add(literalcontrol);

Similar Threads

  1. JavaScript - location.replace
    By Cordaro in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:55 PM
  2. Replies: 6
    Last Post: 13-05-2010, 12:11 PM
  3. JavaScript - open link in same window using location.replace
    By Elizabeth Allen in forum Software Development
    Replies: 7
    Last Post: 13-05-2010, 12:08 PM
  4. javascript replace function not working
    By Cornnelius in forum Software Development
    Replies: 5
    Last Post: 13-05-2010, 12:12 AM
  5. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,615,873.41330 seconds with 17 queries