Results 1 to 20 of 20

Thread: A small URL Bamboozlement [Resolved]

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?
    Last edited by mendhak; Feb 1st, 2005 at 10:35 AM.

  2. #2

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  3. #3
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: A small URL Bamboozlement

    \r\n is a full Cariage Return Line Feed. I dunno though never tried anything like this.
    Magiaus

    If I helped give me some points.

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  5. #5
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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
    Magiaus

    If I helped give me some points.

  6. #6
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    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:
    1. Response.Redirect("webform2.aspx?body=Hello how are \n you!?")

    webform2 (page_load)
    VB Code:
    1. Dim str As String = Request.QueryString("body").ToString
    2.  
    3. str = str.Replace("\n", System.Environment.NewLine)
    4.  
    5. TextBox1.TextMode = TextBoxMode.MultiLine
    6. TextBox1.Text = str

    Image of the output is attached
    Attached Images Attached Images  
    Last edited by rdove; Feb 1st, 2005 at 10:51 AM.
    ~Ryan





    Have I helped you? Please Rate my posts.

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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 ) 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.

  8. #8
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: A small URL Bamboozlement [Resolved]

    Add the \r and you shouldn't need to do anything. The NewLine should be there. \r\n
    Magiaus

    If I helped give me some points.

  9. #9
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    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
    ~Ryan





    Have I helped you? Please Rate my posts.

  10. #10

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: A small URL Bamboozlement [Resolved]

    Alright, that seems interesting.

    I'll try this tomorrow at work and post back.

    Get it? Postback? Bwahahhaha!!!

  11. #11
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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>
    Code:
    TestTestTestTest
    Last edited by Magiaus; Feb 1st, 2005 at 11:18 AM.
    Magiaus

    If I helped give me some points.

  12. #12
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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.
    Magiaus

    If I helped give me some points.

  13. #13

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: A small URL Bamboozlement [Resolved]

    If not request, what do you use then?

  14. #14
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: A small URL Bamboozlement [Resolved]

    The same page. I just load a new control into it.
    Magiaus

    If I helped give me some points.

  15. #15
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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?
    Magiaus

    If I helped give me some points.

  16. #16
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    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.
    ~Ryan





    Have I helped you? Please Rate my posts.

  17. #17
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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.
    Magiaus

    If I helped give me some points.

  18. #18
    Addicted Member rdove's Avatar
    Join Date
    Dec 2002
    Location
    Indianapolis
    Posts
    251

    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.
    ~Ryan





    Have I helped you? Please Rate my posts.

  19. #19

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  20. #20
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    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.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width