A small URL Bamboozlement [Resolved]
I've got a page called SendEmail.aspx. In this page, I am looking for a Request.Querystring value which I put into a multiline asp:textbox.
PHP Code:
if(!(Request.QueryString["body"] ==null))
{
strBody = Request.QueryString["body"].ToString();
strBody = strBody.Replace("\n",System.Environment.NewLine);
}
As you can see, the entire body will be passed in the URL, and I am trying to replace the \n with newlines, so that the textbox has those linebreaks in it.
This is how the call is done:
Code:
javascript:popBox('SendEmail.aspx?body=Hello how are \n you!?');
The problem is, the "\n" is not being replace with a newline. Instead, I get a space.
What can I do to get the NewLines in there for the textbox?
Re: A small URL Bamboozlement
Stepping through the code shows me that the "\n" is being replaced by a space in the query string itself. So I have no access to the "\n", it doesn't exist!
Is there anything else that can be done to "denote" a newline?
Re: A small URL Bamboozlement
\r\n is a full Cariage Return Line Feed. I dunno though never tried anything like this.
Re: A small URL Bamboozlement
I tried \\n, so that \n would be present in the string. Except it didn't get replaced for some odd reason.
Finally, I just went by using {BR} in there, and replacing that.
Strange, strange stuff, but it's resolved. For now. Hopefully.
Thanks.
Re: A small URL Bamboozlement [Resolved]
Yeah, at least you can find that. It's weird though the \n or \r\n should work unless the querystring encode and decode is messing it up.... weirdness
1 Attachment(s)
Re: A small URL Bamboozlement [Resolved]
I don't know why you are having a problem, I just did some testing (in vb.net) and did not have any issues, maybe your circumstance is different somehow.
webform1 (page_load)
VB Code:
Response.Redirect("webform2.aspx?body=Hello how are \n you!?")
webform2 (page_load)
VB Code:
Dim str As String = Request.QueryString("body").ToString
str = str.Replace("\n", System.Environment.NewLine)
TextBox1.TextMode = TextBoxMode.MultiLine
TextBox1.Text = str
Image of the output is attached
Re: A small URL Bamboozlement [Resolved]
I think it's because you're doing Response.Redirect, and I'm passing the URL in a JavaScript popup function. There's obviously something happening at the application level, with the way JS is passing the URL perhaps.
If you open up webform1.aspx, and then type this into the browser:
Code:
javascript:document.location.href='webform2.aspx?body=Hello how are \n you!?';
you should (hopefully :D) have a problem.
What some people reccommended to me was to use %0a and %0d instead, but they make things worse: They actually terminate the string. :sick:
Re: A small URL Bamboozlement [Resolved]
Add the \r and you shouldn't need to do anything. The NewLine should be there. \r\n
Re: A small URL Bamboozlement [Resolved]
I did run into the the same problem, but I Querystrings can handle Hex values and converts some to hex like space is %20
So I converted \ to %5c
Code:
<script language="javascript">
document.location.href='webform2.aspx?body=Hello how are %5Cn you!?';
</script>
and this worked perfectly
Re: A small URL Bamboozlement [Resolved]
Alright, that seems interesting. :)
I'll try this tomorrow at work and post back.
Get it? Postback? Bwahahhaha!!! :lol:
Re: A small URL Bamboozlement [Resolved]
lol, I was wrong about the \r\n but this is funny.
HTML Code:
<body MS_POSITIONING="Flow">
<form id="Form1" method="post" runat="server">
<script>
txt = "Test%5cr%5cnTest%5cr%5cnTest%5cr%5cnTest";
window.document.location.href = "WebForm2.aspx?txt=" + txt;
</script>
</form>
</body>
My Textbox shows
Code:
Test\r\nTest\r\nTest\r\nTest
Even better
HTML Code:
<body MS_POSITIONING="Flow">
<form id="Form1" method="post" runat="server">
<script>
txt = "Test%10%13Test%10%13Test%10%13Test";
window.document.location.href = "WebForm2.aspx?txt=" + txt;
</script>
</form>
</body>
Re: A small URL Bamboozlement [Resolved]
Yeah, I added the Replace and it works fine. I had forgotten about that. I haven't used a Request var in so long; not since back in ASP.
Re: A small URL Bamboozlement [Resolved]
If not request, what do you use then?
Re: A small URL Bamboozlement [Resolved]
The same page. I just load a new control into it.
Re: A small URL Bamboozlement [Resolved]
The javascript adds the newline but there is no way to pass it through the request. That's why there was a problem, but why won't the request handle this?
Re: A small URL Bamboozlement [Resolved]
I think the request object can handle is fine, I think javascript is the problem. \n in javascript denotes a new line, so what I believe is happenning is that javascript is converting the value before it even makes it to the redirection. Since on a javascript redirect you can't have a line break, I think it is parsing it out so it can handle the redirect and not crash the browser.
Re: A small URL Bamboozlement [Resolved]
Quote:
Originally Posted by rdove
I think the request object can handle is fine, I think javascript is the problem. \n in javascript denotes a new line, so what I believe is happenning is that javascript is converting the value before it even makes it to the redirection. Since on a javascript redirect you can't have a line break, I think it is parsing it out so it can handle the redirect and not crash the browser.
That's what I meant.
So, your saying that the javascript just removes it instead of encoding it; since encoding it doesn't work anyway, and the browser could have an invalid request if it actually had the Cariage Return Line Feed or New Line codes. That makes since. It sucks, but it makes since.
Re: A small URL Bamboozlement [Resolved]
Quote:
Originally Posted by Magiaus
So, your saying that the javascript just removes it instead of encoding it; since encoding it doesn't work anyway...
Either that or javascript doesn't know how/support encoding it.
Re: A small URL Bamboozlement [Resolved]
I just realized I made a mistake:
Code:
strBody = strBody.Replace("\\n", System.Environment.NewLine);
That needed two backslashes, of course!
Thanks, both of you. I do appreciate your responses here. :)
Re: A small URL Bamboozlement [Resolved]
I thought that but didn't have time to try it. that escapes the escape and it goes through. Nice.