Using the code
The code contains two segments:
- The utility routine.
Test method demonstrating how to make use of the utility routine.
this.Url = '';
this.Pairs = new Array();
HttpQueryStringBuilder.prototype.GetFullString = function()
var queryString = (this.Url.length > 0) ? this.Url + "?" : '';
for(var key in this.Pairs)
queryString += escape(key) + "=" + escape(this.Pairs[key]) + "&";
return queryString.substring(0, queryString.length - 1);
var builder = new HttpQueryStringBuilder();
builder.Url = "http://www.google.com"
builder.Pairs["FirstName"] = "S M";
builder.Pairs["LastName"] = "Sohan";
builder.Pairs["EMail"] = "firstname.lastname@example.org";
builder.Pairs["FirstName"] = "Sheikh Mohammad";
builder.Pairs["EMail"] = "email@example.com";
To use the supplied test code, you need a markup like this in one of your pages:
<input type="button" value="Button" onClick="Test()" />
- June 30, 2007: Edited for the first time, and submitted as unedited post to CodeProject.