How to pass special characters through query string ?

S

Sobin Thomas

Hi All,
I want to pass a string that contains many special characters :) \ . _
etc) to another page in my website
through query string.
In my project I have a Gridview control ,in which there is a hyperlink
field.The Gridview 's datasource is set as a database table at runtime.The
hyperlink filed's DataNavigateUrlFields is set to "RecordID" ,which is a
field in my database table.The RecordID field contains many special
characters.I want to pass the RecordID to PlayRecord.aspx page .I transfer
the RecordID by setting Hyperlink field's Data NavigateUrlFormat string as
PlayRecord.aspx?RecID={0}.The problem is that, hyperlinks are not working as
RecordID contains special characters.(It works if RecordID is a normal
string).
Hope you 'll surely have a solution.
Thanking you in advance for your reply.
Best Regards
 
A

Anthony Jones

Sobin Thomas said:
Hi All,
I want to pass a string that contains many special characters :) \ . _
etc) to another page in my website
through query string.
In my project I have a Gridview control ,in which there is a hyperlink
field.The Gridview 's datasource is set as a database table at runtime.The
hyperlink filed's DataNavigateUrlFields is set to "RecordID" ,which is a
field in my database table.The RecordID field contains many special
characters.I want to pass the RecordID to PlayRecord.aspx page .I transfer
the RecordID by setting Hyperlink field's Data NavigateUrlFormat string as
PlayRecord.aspx?RecID={0}.The problem is that, hyperlinks are not working as
RecordID contains special characters.(It works if RecordID is a normal
string).
Hope you 'll surely have a solution.
Thanking you in advance for your reply.

This group is for Classic ASP. For ASP.NET questions post to
microsoft.public.dotnet.framework.aspnet
 
B

Bob Barrows [MVP]

Sobin said:
Hi All,
I want to pass a string that contains many special characters :) \ . _
etc) to another page in my website
through query string.
In my project I have a Gridview control ,in which there is a hyperlink
field.The Gridview 's datasource is set as a database table at
runtime.The hyperlink filed's DataNavigateUrlFields is set to
"RecordID" ,which is a field in my database table.The RecordID field
contains many special characters.I want to pass the RecordID to
PlayRecord.aspx page .I transfer the RecordID by setting Hyperlink
field's Data NavigateUrlFormat string as
PlayRecord.aspx?RecID={0}.The problem is that, hyperlinks are not
working as RecordID contains special characters.(It works if RecordID
is a normal string).

The solution is the same for dotnet as it is for COM-based ASP: use the
urlEncode method to encode the strings being put into the querystring.
Having said that:

There was no way for you to know it (except maybe by browsing through some
of the previous questions in this newsgroup before posting yours - always a
recommended practice) , but this is a classic (COM-based) asp newsgroup.
ASP.Net bears
very little resemblance to classic ASP so, while you may be lucky enough to
find a dotnet-knowledgeable person here who can answer your question, you
can eliminate the luck factor by posting your question to a group where
those dotnet-knowledgeable people hang out. I suggest
microsoft.public.dotnet.framework.aspnet or the forums at www.asp.net.
 
A

Anthony Jones

Bob Barrows said:
The solution is the same for dotnet as it is for COM-based ASP: use the
urlEncode method to encode the strings being put into the querystring.


How easy is that to achieve when databinding into a gridview? I don't use
the provided controls much myself. I suspect one would need to add a field
to the datasource that has the value UrlEncoded. Better would be to not use
such a value and use a numeric, hash or guid instead.
 
B

Bob Barrows [MVP]

Anthony said:
How easy is that to achieve when databinding into a gridview? I
don't use the provided controls much myself.

I hadn't really thought it through. I suppose he would have to use a
templatefield object rather than a boundfield object so the object can
be bound to the result of the UrlEncode function.
I suspect one would
need to add a field to the datasource that has the value UrlEncoded.

That's one of the options I was thinking of.
Better would be to not use such a value and use a numeric, hash or
guid instead.
I can't argue with that.
 
M

Mike Brind [MVP]

Bob Barrows said:
I hadn't really thought it through. I suppose he would have to use a
templatefield object rather than a boundfield object so the object can
be bound to the result of the UrlEncode function.

Or you could simply format the value in the control's RowDataBound event....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top