0

Possible Duplicate:
Get query string values in JavaScript

What is the best way to get "test1" from

http://localhost:3311/blabl/allprofiles.aspx?username=test1

, and through PageMethod pass it to webmethod. I think one way is to take from window.location.pathname, cut the string and pass it like a parameter.

Community
  • 1
  • 1
gormit
  • 807
  • 3
  • 9
  • 29
  • Take a look here: http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript – Mrchief Jul 05 '11 at 20:05

2 Answers2

1

May be you can use only javascript like:

var search = function(){
  var s = window.location.search.substr(1),
      p = s.split(/\&/),
      l = p.length, 
      kv, r = {};
  if(l === 0){return false;}
    while(l--){
      kv = p[l].split(/\=/);
      r[kv[0]] = kv[1] || true;
    }
    return r;
}();

Then use in your code search.username

Mic
  • 24,812
  • 9
  • 57
  • 70
0

Try

string username = Request.QueryString["username"];

In a PageMethod, you can do

string username = HttpContext.Current.Request.QueryString["username"];
Bala R
  • 107,317
  • 23
  • 199
  • 210