When I Press Enter Key than Auto Write <BR> Tags

Discussion in 'C#' started by knisarmughal, Sep 17, 2008.

  1. #1
    hello!


    i have form for submission articles i want to use <br> tag at the end of paragraph. please tell to me how is possible. when i press Enter Key at the end of paragraph than ASP Form Develop Auto <br> Tag in the database. because database show articles in paragraph with <br>tag

    how is possible.............................
     
    knisarmughal, Sep 17, 2008 IP
  2. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #2
    Here's how I tackle it:

    User enters body of text in memo field
    code performs security checks
    if security checks pass, then insert text directly to database
    when code is rendered back to browser, do this:

    MyText = Replace(MyText,vbcrlf,"<br />")

    This handy little guy will put the <br /> tag where ever it encounters a hard return in the text.
     
    dwirch, Sep 18, 2008 IP
  3. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #3
    btw - I don't think it's a good idea to store the html in the database with the text. If you ever want to use that text in a different application, say a word document, then your going to have to strip the html out to make it readable to humans.

    IMHO, it's much easier to 'massage' the output from the database with some code.
     
    dwirch, Sep 18, 2008 IP
  4. knisarmughal

    knisarmughal Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hello Dwirch!


    what you want tell to me i can't understand please try to slowly learn to me with example

    thanks.....

     
    knisarmughal, Sep 23, 2008 IP
  5. dwirch

    dwirch Well-Known Member

    Messages:
    239
    Likes Received:
    12
    Best Answers:
    1
    Trophy Points:
    135
    #5
    I can only tell you how I have done it in the past. This method may or may not fit with your code.

    When storing the information in the database, store the raw data.

    But when retrieving it, put into a variable first, so you can work with it.

    Here is a simplified version of some code that is currently live:

    <div id="content">
    	<%
    
    	'open database connection
    
    	strSQL = "SELECT * FROM tblNews WHERE NewsID=" & MyNewsID
    	objConn.Open		              
    	Set rstResults=objConn.Execute(strsql)
    
    	'set variables
    
    	Dim NewsTitle
    	Dim DateEntered
    	Dim NewsBody
    
    	'grab content from database
    
    	NewsTitle=rstResults("NewsTitle")
    	NewsBody=rstResults("NewsBody")
    	DateEntered=rstResults("NewsPostDate")
    
    	'close database
    
    	rstResults.Close
    	objConn.Close
    
    	'add breaks
    
    	NewsBody=Replace(NewsBody,vbcrlf,"<br />")
    
    	'send output to browser
    
    	%>
    	<h3><% =NewsTitle %></h3>
    	<p><% =DateEntered %></p>
    	<hr>
    	<p><% =NewsBody %></p>
    </div>
    Code (markup):
    So the flow is basically as described previously. Grab the data, replace the cr/lf with the <br /> tag, and send it to the browser.
     
    dwirch, Sep 23, 2008 IP