C
C.
I should know this already, but I'm exhausted and I was out of coffee
this morning
A have a pager that allows me to page through a dataset, and I print
off some links at the bottom so users can jump between pages.
When I build the links, I URL encode the hrefs so I get XHTML-
compliant pages:
StringBuilder queryString = new StringBuilder();
queryString.Append("adminID=" + adminID);
queryString.Append("&userPage=" + userPage);
return Server.URLEncode(String.Format("Home.aspx?{0}",
queryString.ToString()));
This produces: <a href="/Home.aspx%3fadminID%3d1%26userPage%3d2">2</a>
When I click that link, I get a terse Bad Request message (no
exception, no stack trace, just "Bad Request")
I tried HTML Encoding the URL, so I end up with:
<a href="/Home.aspx?adminID=1&userPage=2>2</a>
Unfortunately, when the link is clicked, the querystring variables is
not retrieved as expected.
if (!Int32.TryParse(Request.QueryString["userPage"], out userPage))
{
//This part I really don't want to run, but I do when I am
parsing a URL Encoded querystring
userPage = 1
}
Looking at the Querystring object, the key of interest is
"amp;userPage", not "userPage" as expected. I presume I need to run
decode the key, but I'm kinda flummoxed as to how to do that.
I could assign the Querystring to a NameValueCollection, tearing out
the offending "amp;" prefix as I do, but that doesn't seem especially
elegant. Is there a cleaner way to achieve what i want?
Cheers,
C.
this morning
A have a pager that allows me to page through a dataset, and I print
off some links at the bottom so users can jump between pages.
When I build the links, I URL encode the hrefs so I get XHTML-
compliant pages:
StringBuilder queryString = new StringBuilder();
queryString.Append("adminID=" + adminID);
queryString.Append("&userPage=" + userPage);
return Server.URLEncode(String.Format("Home.aspx?{0}",
queryString.ToString()));
This produces: <a href="/Home.aspx%3fadminID%3d1%26userPage%3d2">2</a>
When I click that link, I get a terse Bad Request message (no
exception, no stack trace, just "Bad Request")
I tried HTML Encoding the URL, so I end up with:
<a href="/Home.aspx?adminID=1&userPage=2>2</a>
Unfortunately, when the link is clicked, the querystring variables is
not retrieved as expected.
if (!Int32.TryParse(Request.QueryString["userPage"], out userPage))
{
//This part I really don't want to run, but I do when I am
parsing a URL Encoded querystring
userPage = 1
}
Looking at the Querystring object, the key of interest is
"amp;userPage", not "userPage" as expected. I presume I need to run
decode the key, but I'm kinda flummoxed as to how to do that.
I could assign the Querystring to a NameValueCollection, tearing out
the offending "amp;" prefix as I do, but that doesn't seem especially
elegant. Is there a cleaner way to achieve what i want?
Cheers,
C.