Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Losing Paragraph shape using ASP

Options
  • 08-09-2009 5:22pm
    #1
    Registered Users Posts: 224 ✭✭


    Hi,
    Im inserting data into a SQL2000 table with breaks/paragraphs and returning it on an ASP (VBScript) page without the breaks.

    The information is going into the table as follows;

    The quick brown fox jumps
    over a lazy dog. The quick brown
    fox jumps over a lazy dog.

    But its returning like so

    The quick brown fox jumps over a lazy dog. The quick brown fox jumps over a lazy dog.

    Basically its not holding its inserted structure when its being returned to the page. Is there any coding i can use to keep its structure.


Comments

  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    The problem here is whitespace is not recognised by the web browser. Your text is going in with a line break at the end of each sentence (which is how it would display in a textarea box for example) and this is being returned from the database. However, the web browser ignores the line break as it's a non-html character (the <br /> tag is used to generate this effect in HTML). There are a number of options for you:
    1. Get the data to be outputted as the input value of a textarea
    2. Replace all the linebreaks with <br />

    The second is probably the better option. There is a vbscript function called replace if I remember correctly (http://www.devguru.com/Technologies/vbscript/quickref/replace.html) that you can use to format the result of the query to look the way you want or you can have a look into a topic called regular expressions if you're using javascript to get the same effect (http://www.regular-expressions.info/).

    Regards,
    RD


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Or just wrap <pre> tags around the output, but doing the replace as Ron suggests is probably the easiest.

    Can't remember which of the two linebreaks to use, but just try both and see which one works.
    sText = <value from database>
    sText = Replace(sText, vblf, "<br/>")
    sText = Replace(sText, vbcrlf, "<br/>")
    


  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    Hi Eoin,

    I have tried those both (see below) and am getting an error back

    <%
    Dim sText = Request.QueryString("<%=(rsEditStory.Fields.Item("MainBody").Value)%>")

    sText = Replace(sText, vblf, "<br/>")
    %>
    <%
    Dim sText = Request.QueryString("<%=(rsEditStory.Fields.Item("MainBody").Value)%>")

    sText = Replace(sText, vbcrlf, "<br/>")
    %>
    *******

    Error Type:
    Microsoft VBScript compilation (0x800A0401)
    Expected end of statement
    viewStory.asp, line 219, column 10
    Dim sText = Request.QueryString("<%=(rsEditStory.Fields.Item("MainBody").Value)
    ^
    Any ideas what im doing wrong


    I also tried the <pre> tag. That put in the breaks but it push the predermined <td> witdh out of proportion.

    <pre> <%=(rsEditStory.Fields.Item("CoisteMainBody").Value)%></pre>


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    This doesn't work in ASP. You need to declare it first, and use it later.
    Dim sText = Request.QueryString("<%=(rsEditStory.Fields.Item("MainBody").Value)
    

    It needs to be:
    Dim sText 
    sText = Request.QueryString("<%=(rsEditStory.Fields.Item("MainBody").Value)
    
    I also tried the <pre> tag. That put in the breaks but it push the predermined <td> witdh out of proportion.

    Then just do the search and replace.


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Why are you using Request.QueryString()? That's used to get query parameters from the request object.

    I think what you want is something like
    sText = rsEditStory.Fields.Item("MainBody").Value
    to get the value from your DB field into sText.


  • Advertisement
  • Registered Users Posts: 224 ✭✭The Mighty Dubs


    cheers for that...

    I tried this


    <%
    Dim sText = (recordset1.Fields.Item("MainBody").Value)
    sText = Replace(sText, vblf, "<br/>")
    %>

    but am getting this error

    Microsoft VBScript compilation error '800a0401'
    Expected end of statement
    /test/test.asp, line 309

    Dim sText = (recordset1.Fields.Item("MainBody").Value)
    ^


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    I already answered this in post #5


  • Moderators, Politics Moderators Posts: 39,846 Mod ✭✭✭✭Seth Brundle


    *cough*SQL Injection*cough*


Advertisement