473,659 Members | 3,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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&Sea rchString=Tax&M inRelevance=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.Quer yString x = new System.Web.Quer yString();
x.Add("State", State);
x.Add("SearchSt ring", SearchString);
x.Add("MinRelev ance", MinRelevance);
return (x.ToString());

At the moment, I am looking at writing my own function to
do this. It will take a namevaluecollec tion, and iterate
through those, creating the querystring. Then I would
have to use System.Web.Http Utility.UrlEnco de. 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 5193
David wrote:
"?State=ACT&Sea rchString=Tax&M inRelevance=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&Sea rchString=Tax&M inRelevance=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.Qu eryString 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.Collecti ons.Specialized ;

namespace ITR.Web.HttpUti lity
{
/// <summary>
/// Summary description for QueryString.
/// </summary>
public class QueryString : NameValueCollec tion
{

private string _queryStringSta rtChar
= "?";
private string _queryStringSep aratorChar
= "&";

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

// Only fill the Stringbuilder if
there are values in the NameValueCollec tion
if (this.Count > 0)
{
// Add the questionmark
ReturnValue.App end
(_queryStringSt artChar);

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

ReturnValue.App end(_queryStrin gSeparatorChar) ;

// Add the next
value
ReturnValue.App end
(System.Web.Htt pUtility.UrlEnc ode(Key) + "=" +
System.Web.Http Utility.UrlEnco de(this[Key].ToString()));
}
}

return (ReturnValue.To String());
}

} // QueryString

} // ITR.Web.HttpUti lity
=============== =============== ======

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
10606
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 and branchcode guess something like CREATE TABLE & Request.querystring("name") branchname. branchcode.
1
1496
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 several times to perform this kind of action, maybe it just needs some fresh eyes :) The code i'm using is as follows: Class cURL ' *--- --------------------------------------------------* Private i_ItemCount
3
10796
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 then like that, when clicking the LinkButton, the user can be navigated to another page, carrying a variable. I would like to use server.transfer method instead of QueryString as I don't want the carried variable to be visible for the user.
12
5286
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 ... www.something.com/main.aspx?client Client is the QueryString, but no value is given. This would mean to me that client exists, so its value is true. In the code behind, I can tell that client exists using Request.QueryString.Keys.Count, which equals 1....
3
1324
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 = Request.QueryString("search").Split(CChar("")) It's not working. What am I doing wrong?
4
1607
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 while the query runs. I don't know much about threading, so bear with me. The following code contains a class that works fine when threading is not used, but fails to return a dataset when I execute the threading code. Any help would be appreciated....
3
8172
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. I want to create an standard url for the website which includes my username and password so I don't have to type it in everytime. I looked at the page source but I can't find the right string.
3
2155
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 must be submitted with a unique key, while everything is the same, these 4 fields must be different.... Idealy, these are the codes. please teach me how to do it. objConn.Open(sConnection) sRowNum = request.querystring("row_num")
2
3458
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 website from our old system to sharepoint, and now one of her links is broken. It is a simple ASP page with parameters that uses VB script to create an Excel object and load an Excel file into it (wb name, sheet name, and scroll number are the ASP...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8628
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.