Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,
when redirecting to page i am passing two query string value.I have home button in redirected page when i click on it i am redirecting to same page but i am loosing query string value.
can any one help me to solve it

What I have tried:

C#
protected void home_ServerClick(object sender, EventArgs e)
        {
            // var nameValues = HttpUtility.ParseQueryString(Request.QueryString.ToString());
         //   string url = Request.Url.AbsolutePath;
        int    userid = Convert.ToInt32(Decrypt(HttpUtility.UrlDecode(Request.QueryString["u"])));
        string salt = Decrypt(HttpUtility.UrlDecode(Request.QueryString["s"])).ToString();

        string u = HttpUtility.UrlEncode(Encrypt(userid.ToString()));
        string s = HttpUtility.UrlEncode(Encrypt(salt));
           // Response.Redirect(url + "?" + nameValues);

       //   Response.Redirect("kgis.aspx?u=" + u + "&s=" + s);

        string url = HttpContext.Current.Request.Url.AbsoluteUri;

        string[] separateURL = url.Split('?');
        NameValueCollection queryString = System.Web.HttpUtility.ParseQueryString(separateURL[1]);
        queryString["u"] = u;
        queryString["s"] = s;
        url = separateURL[0] + "?" + queryString.ToString();
        Response.Redirect(url);
        }
Posted
Updated 5-Dec-16 13:14pm
Comments
$*Developer - Vaibhav*$ 5-Dec-16 4:52am    
Please share designer code & also check which event u r calling?
preety sunita 5-Dec-16 7:28am    
If you are getting query string values for 'u' and 's' variable then it should be redirected from there..?? Is there any exception coming when plain response.redirect code is using by you..?
ZurdoDev 5-Dec-16 7:50am    
1. You don't need to urldecode Request.QueryString. It already does it for you. You can mess up certain characters decoding twice.
2. This is very simple. Get the query string values and then add them to the url you want to go to. Where is the problem?

1 solution

I suggest when your redirected page loads, change the href attribute of the home button to include the query string which is passed to the page. You can do this using jQuery as;

JavaScript
var urlValue = window.location.href;
$('#homebutton').attr('href',urlValue);
 
Share this answer
 
Comments
David A. Gray 31-Jan-23 0:31am    
Thank you for inspiring the solution that I needed to a similar issue.

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