473,320 Members | 1,794 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Easily create a querystring on the fly?

Hello

I need to take some values and place them in a string in
the format of a querystring.

Lets say I have:

string State = "ACT";
string SearchString = "Tax";
int MinRelevance = 50;

I want to create the string:

"?State=ACT&SearchString=Tax&MinRelevance=50"

This will then be placed on the end of the relevant URL,
and placed in an anchor tag on the resulting page, so the
user can click on that link.

Now in an ideal world, I would be able to do:

System.Web.QueryString x = new System.Web.QueryString();
x.Add("State", State);
x.Add("SearchString", SearchString);
x.Add("MinRelevance", MinRelevance);
return (x.ToString());

At the moment, I am looking at writing my own function to
do this. It will take a namevaluecollection, and iterate
through those, creating the querystring. Then I would
have to use System.Web.HttpUtility.UrlEncode. I would
assume I will have to add on a dummy URL and remove it
after the UrlEncode as well.

Anyway, if there is an object function somewhere that
already does this, I would love to hear about it.

Thanks
David
Nov 18 '05 #1
5 5175
David wrote:
"?State=ACT&SearchString=Tax&MinRelevance=50"


There's always string.Format. Yould also use the Cache, Application and
Session objects to avoid passing that information so visibly.

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 18 '05 #2
No, I actually want that data in the querystring. People
should be able to right click on the link and bookmark
them. The info is entered by the user, so does not need
to be secure.

I cannot see how string.format will help me. I really
want to use the Querystring Object without it being
linked to an actual web page. It is so easy wo add new
values to the querystring of an actual page, but nothing
to help you if you want to build querystrings for 10
links on a page.

David

-----Original Message-----
David wrote:
"?State=ACT&SearchString=Tax&MinRelevance=50"
There's always string.Format. Yould also use the Cache,

Application andSession objects to avoid passing that information so visibly.
--
There are 10 kinds of people. Those who understand binary and those whodon't.

http://code.acadx.com
(Pull the pin to reply)
.

Nov 18 '05 #3
Hi David,

I am not sure where you want to append the querystring to a URL. As I
understood, if you want to change the action property of this webform by
appending the querystring, you can override the Render method, where you
can replace the name of current web form with the same one followed by the
querystring.

If I have misunderstood your concern, please feel free to let me know.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #4
Thats not what I wanted.

I have created an object to do the trick. Code is posted
here for anyone else who wants this functionality.

Jacob, if there is an object in the framework that
already does this, let me know. And the
Page.Request.QueryString is no good, as I am not adding
this querystring to the current page. I am making up 10
different links to place in anchors on the web page. I
must make a querystring for each of these 10 links.

==================================
using System;
using System.Collections.Specialized;

namespace ITR.Web.HttpUtility
{
/// <summary>
/// Summary description for QueryString.
/// </summary>
public class QueryString : NameValueCollection
{

private string _queryStringStartChar
= "?";
private string _queryStringSeparatorChar
= "&";

/// <summary>
/// Returns a UrlEncoded Querystring
representation of the values in the namevaluecollection
/// </summary>
/// <returns></returns>
public override string ToString()
{
System.Text.StringBuilder
ReturnValue = new System.Text.StringBuilder();
bool FirstValue = true;

// Only fill the Stringbuilder if
there are values in the NameValueCollection
if (this.Count > 0)
{
// Add the questionmark
ReturnValue.Append
(_queryStringStartChar);

// Add all the values in
the NameValueCollection
foreach (string Key in
this.AllKeys)
{
// Add an
ampersand if this is not the first value
if (!FirstValue)

ReturnValue.Append(_queryStringSeparatorChar);

// Add the next
value
ReturnValue.Append
(System.Web.HttpUtility.UrlEncode(Key) + "=" +
System.Web.HttpUtility.UrlEncode(this[Key].ToString()));
}
}

return (ReturnValue.ToString());
}

} // QueryString

} // ITR.Web.HttpUtility
====================================

David

-----Original Message-----
Hi David,

I am not sure where you want to append the querystring to a URL. As I understood, if you want to change the action property of this webform by appending the querystring, you can override the Render method, where you can replace the name of current web form with the same one followed by the querystring.

If I have misunderstood your concern, please feel free to let me know.
Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
.

Nov 18 '05 #5
Hi David,

Thank you for sharing your wonderful solution.

I have done more research regarding this issue. Unfortunately, there is not
such a .NET Framework class that can do the same functionality. Thank you
for your understanding.

Best regards,

Jacob Yang
Microsoft Online Partner Support
Get Secure! ¨C www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob | last post by:
Hi all, Quick question, how do you create a table in MS Access from with an asp script? I will be creating the table name from Request.querystring("name"), also needs fields of branchname...
1
by: Colin Mc Mahon | last post by:
Hi, I am trying to re-write an old url management class I use, and am having problems using the Execute method to create vars. I think i'm missing something simple, as I have used this method...
3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
12
by: Alex | last post by:
I have a question about determining if one QueryString keys exists. The idea is, if this key exists, than its presence is enough to indicate that its value is true. For example ... ...
3
by: Miguel Dias Moura | last post by:
Hello, I am calling an ASP.NET / VB as follows: search.aspx?search=asp%20book%20london Then I create a string with the keywords like this: Dim keywords() As String =...
4
by: Lee Moore | last post by:
I am trying to develop a threaded function to create a dataset from an Oracle database. When querying an elaborate view, queries take a while. I would like to place and animated wait dialog up...
3
by: Co | last post by:
Hi All, I use a website in asp for which I have to type a username and password everytime I want to login. On the form are two fields for typing the username and password and one button LOGIN....
3
by: pingsheng | last post by:
Dear all, I have a form with dynamically created input fields. These fields go to next page for submitting into SQL database. The thing is all fields are the same but 4 fields. So each record...
2
by: stjones1 | last post by:
My company has implementd Vista with IE7 and office 2007. We also use Sharepoint extensively for team sites and division portals. I am in Sharepoint consultation/support. One user just moved a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.