Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
Take a look here: stackoverflow.com/questions/901115/… – Mrchief Jul 5 '11 at 20:05

marked as duplicate by Eugene Mayevski 'EldoS Corp, bažmegakapa, Jeff Atwood Jul 6 '11 at 11:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 1 down vote accepted

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

share|improve this answer

Try

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

In a PageMethod, you can do

string username = HttpContext.Current.Request.QueryString["username"];
share|improve this answer
Yes, I try second one but I get null. – gormit Jul 5 '11 at 20:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.