Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

URL displaying %20 for spaces

Posted on 2008-06-23
8
Medium Priority
?
234 Views
Last Modified: 2013-12-16
In IE browser and some other browsers The URL is dispaying "%20" for spaces.

Passing date, month and headline in a query string (attached code).

In the headline text, it strips the space and replaces it with %20. Why so??Any help

How can I fix this thing.

Would appreciate any help!

 

Thanks!
private void RenderRelease(HtmlTextWriter xwriter, PressRelease release) {
			if (xwriter == null) {
				throw new ArgumentNullException("xwriter");
			}
 
			if (release == null) {
				throw new ArgumentNullException("release");
			}
 
			xwriter.RenderBeginTag(HtmlTextWriterTag.Li);
 
			parms[0] = release.Dateline.Year.ToString(cc);
			parms[1] = release.Dateline.ToString("MMMM",cc);
			parms[2] = release.Headline;
 
			HyperLink link = new HyperLink();
			link.NavigateUrl = FormatHyperlink(PageConstants.PagePressReleaseDetail, false, parms);
			link.Text = release.Headline;
			link.CssClass = "pressRelease";
			link.RenderControl(xwriter);
 
			xwriter.AddAttribute(HtmlTextWriterAttribute.Class, "date");
			xwriter.RenderBeginTag(HtmlTextWriterTag.Span);
			xwriter.WriteEncodedText(String.format(NewsDateForamtString, release.Dateline));
			xwriter.RenderEndTag();		// span
 
			xwriter.RenderEndTag();		// li
		}

Open in new window

0
Comment
Question by:newaspdotnet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
burakiewicz earned 1500 total points
ID: 21849117
that is the html encoding for a space

to set the text use this
headline.Text=HttpUtility.HtmlDecode(strHeadline)
0
 
LVL 26

Expert Comment

by:MidnightOne
ID: 21849134
URLs cannot contain spaces, and therefore puts int he hexadecimal code for space %20 (32 decimal).
0
 

Author Comment

by:newaspdotnet
ID: 21849747
I changed this line of code.

parms[2] = HttpUtility.HtmlDecode(release.Headline);

link.NavigateUrl = FormatHyperlink(PageConstants.PagePressReleaseDetail, false, parms);


Passing this link url as query string.
But this didnt help!

Am I doing this right?
0
Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 16

Expert Comment

by:burakiewicz
ID: 21849883
you need to change it where you set the text or if you have a setter.
You will need to decode it before you use it as text
release.Headline=HttpUtility.HtmlDecode(release.Headline);

or
HyperLink link = new HyperLink();
link.NavigateUrl = FormatHyperlink(PageConstants.PagePressReleaseDetail, false, parms);
link.Text = HttpUtility.HtmlDecode(release.Headline);
link.CssClass = "pressRelease";
link.RenderControl(xwriter);
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 21850031
the navigate url will always have  %20 for a space
0
 

Author Comment

by:newaspdotnet
ID: 21850557
Thanks alot for your help dear!

But I tried doing it both ways you mentioned.

It still gives %20 in the url. :(

Any other way I can try to work this out???


URLSPACE.jpg
0
 

Author Comment

by:newaspdotnet
ID: 21850645
Hey we are already using this in format hyperlink method!!!!!!
My bad I didnt debug it properly earlier.

But now if we are already using "HttpUtility.UrlEncode(argList[i])" then this problem should not be there.

Would really appreciate any help!

public static string FormatHyperlink(string destination, bool useQueryStringParams, params string[] args)
		{
			if (StringHelper.IsNullEmptyOrSpaces(destination))
			{
				throw new ArgumentNullException(destination);
			}
 
			Page p = HttpContext.Current.CurrentHandler as Page;
			if (p != null)
			{
				destination = p.ResolveUrl(destination);
			}
 
			System.Text.StringBuilder result = new System.Text.StringBuilder(destination);
 
			System.Collections.Specialized.StringCollection argList = new System.Collections.Specialized.StringCollection();
			argList.AddRange(args);
			if (useQueryStringParams)
			{
				result.Append("?");
				if (argList.Count % 2 != 0)
				{
					throw new ArgumentOutOfRangeException("args");
				}
 
				for (int i = 0; i < argList.Count - 1; i = i + 2)
				{
					result.AppendFormat("{0}={1}&", HttpUtility.UrlEncode(argList[i]), HttpUtility.UrlEncode(argList[i + 1]));
				}
				result.Remove(result.Length - 1, 1);
			}
			else
			{
				for (int i = 0; i < argList.Count; i++)
				{
					result.AppendFormat("/{0}", HttpUtility.HtmlEncode(argList[i]));
				}
			}
 
			return result.ToString();
		}

Open in new window

0
 

Author Comment

by:newaspdotnet
ID: 21856365

I just changed the following line: result.AppendFormat("/{0}", HttpUtility.HtmlEncode(argList[i]));

TO:

for (int i = 0; i < argList.Count; i++)
                {
                    result.AppendFormat("/{0}", HttpUtility.UrlEncode(argList[i]));
                }

Instead of HtmlEncode I used UrlEncode. It changes %20 to '+' but now I get following error when I click on the hyperlink control....

Did I do something wrong???

Description: The request filtering module is configured to deny a request that contains a double escape sequence.
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question