Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8671815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:02:44+00:00 2026-06-12T19:02:44+00:00

I am trying to make a client side click and redirect to another site

  • 0

I am trying to make a client side click and redirect to another site with header information added, my client side code for the onclick is this:

function selectApp(appGUID, userId ,embedUrl)
{
    if(embedUrl==="")
    {
        var success = setAppGUID(appGUID);
        window.location.replace('AppDetail.aspx');
    }
    else
    {   
        $.ajax({
            type: "POST",
            url: embedUrl,
            contentType: "text/html",
            beforeSend: function (xhr, settings) {
                xhr.setRequestHeader("UserId", userId);
            },
            success: function (msg) {
                //actually redirect to the site
                window.location.replace(embedUrl);
            }
        });
    }  
}

And the server side code in embedUrl is

protected void Page_Load(object sender, EventArgs e)
{
    string isSet = (String)HttpContext.Current.Session["saveUserID"];
    if (String.IsNullOrEmpty(isSet))
    {
        NameValueCollection headers = base.Request.Headers;
        for (int i = 0; i < headers.Count; i++)
        {
            if (headers.GetKey(i).Equals("UserId"))
            {
                HttpContext.Current.Session["saveUserID"] = headers.Get(i);
            }
        }
    }
    else
    {
        TextBox1.Text = HttpContext.Current.Session["saveUserID"].ToString();
    }
}

This seems to work but it’s not too elegant. Is there a way to redirect with header data? Without (what I’m doing) saving header info in a session var then doing a redirect in 2 seperate pieces.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:02:45+00:00Added an answer on June 12, 2026 at 7:02 pm

    You can implement a page method and post data to it.
    Moving your current logic in that method.

    See these examples:

    • http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/

    • http://www.asp.net/ajaxlibrary/jquery_webforms_Post_Data_To_PageMethod.ashx

    Upon successful post you can redirect to another page like your current implementation.

    Edit: Try something like this:

    1) Add a Web method in Code behind

      [WebMethod]
      public static string SaveUserId(string userId)
      {
        string sessionUserId= (string)HttpContext.Current.Session["saveUserID"];
        if (string.IsNullOrEmpty(sessionUserId))
          HttpContext.Current.Session["saveUserID"] = userId;
        else
          TextBox1.Text = sessionUserId;
      }
    

    2) Call it from JS

     //Add here code before..
     $.ajax({
                    url: "PageName.aspx/SaveUserId",
                    data: "{'userid':" + userid + "}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json"
                    success: function (msg) {
                        //actually redirect to the site
                        window.location.replace(embedUrl);
                    }
                });
    

    More on calling Page methods with jQuery:

    • http://deebujacob.blogspot.in/2012/01/aspnet-ajax-web-method-call-using.html
    • http://www.misfitgeek.com/calling-web-service-page-methods-with-jquery/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a multithreaded server/client app with java ! this code is
I am trying to make some edits to a site for a client of
I am trying to make a simple client-server chat program. On the client side
I was trying to make a Cherry Py page that would redirect the client
I'm having an issue trying to make a client side validation on yii 1.1.12.
I am trying to make a server-client model in which the server can see
I am trying to make a Delphi client (Delphi 2006) to communicate with a
I'm trying to make a simple Jabber client using the libstrophe library. It's going
I am trying to make a simple twitter client in C. I'm new at
Hoi! I trying to make a webservice in Windows. The client is Delphi 6,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.