HTML converted to ASCII when saved in SQL

Last post 03-24-2006, 9:55 AM by airstream345. 1 replies.
Sort Posts: Previous Next
  •  03-24-2006, 12:19 AM 17536

    HTML converted to ASCII when saved in SQL

     Hello...me again.  I'm trying to save my HTML from CE into a database table in DNN 4.0.  I bascaily pass my CE.Text value into my stored procedure and update the table for this module.  (I"m storing templates).  But, wht is stored in SQL looks like the ASCII version of HTML and when I recall this data to a literal control...it's the HTML code itself (not redered HTML)
     
    Here is what I enter into the editor:
     
    Stock No
    {InventoryStockNumber}
    Year
    {InventoryYear}
    Brand
    {InventoryManufacturerName}
    Model
    {InventoryBrand}

    Here is my codebehind procedure call:

    Dim dsTemplate As DataSet
    Dim MyConn As SqlConnection
    Dim daTemplate As SqlDataAdapter
    MyConn = New SqlConnection(ConfigurationManager.ConnectionStrings("DNNConnectionString").ConnectionString)
    daTemplate = New SqlDataAdapter("MRVA_Insert_InventoryDetailTemplates", MyConn)
    daTemplate.SelectCommand.CommandType = CommandType.StoredProcedure

    daTemplate.SelectCommand.Parameters.Add(New SqlParameter("@ModuleID", SqlDbType.Int, 4))daTemplate.SelectCommand.Parameters("@ModuleId").Value = ModuleId

    daTemplate.SelectCommand.Parameters.Add(New SqlParameter("@TemplateHTML", SqlDbType.Text))daTemplate.SelectCommand.Parameters("@TemplateHTML").Value = teTemplate.Text

    dsTemplate = New DataSet
    daTemplate.Fill(dsTemplate, "MRVA_InventoryDetailTemplates")

    NOTE- It's a dataset becuase I do some more things with this data later on.
    REM - do more work here

    daTemplate.Dispose()
    MyConn.Close()
     
     
    Here is what is stored in SQL:
     
    <table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=3 border=1>
        <tbody>
            <tr>
                <td>Stock No</td>
                <td>{InventoryStockNumber}</td>
                <td>Year</td>
                <td>{InventoryYear}</td>
            </tr>
            <tr>
                <td>Brand</td>
                <td>{InventoryManufacturerName}</td>
                <td>Model</td>
                <td>{InventoryBrand}</td>
            </tr>
        </tbody>
    </table>

    Here is what is displayed in my literal on the View control for this module:
     
    (Note: the tokesn {InventoryStockNo} are replaced with real data beforehand.
     
    <table style="WIDTH: 100%; BORDER-COLLAPSE: collapse" cellSpacing=0 cellPadding=3 border=1> <tbody> <tr> <td>Stock No</td> <td>STOCKNO</td> <td>Year</td> <td>1986</td> </tr> <tr> <td>Brand</td> <td>Airstream </td> <td>Model</td> <td>Classic</td> </tr> </tbody> </table>
     
    I know this is probably something really silly, but for the life of me I can't figure it out.  IT found some references in the forums to similar problems and links to examples...but the example don't show any code samples.
     
    Is the literal the right control for this?  Should I be rendering in something else with an innerHTML propery?
     
    Any advice would be appreciated!
  •  03-24-2006, 9:55 AM 17561 in reply to 17536

    Re: HTML converted to ASCII when saved in SQL

    I managed to solve my own problem just by getting some sleep and looking at this again in the morning.  The solution is to make sure I use Server.HTMLDecode when inserting into the db and again when extracting the html before rendering it in the span:
     
    SQL Parameter Insert changed to this:
     
    daTemplate.SelectCommand.Parameters.Add(New SqlParameter("@TemplateHTML", SqlDbType.Text))daTemplate.SelectCommand.Parameters("@TemplateHTML").Value = Server.HTMLDecode(teTemplate.Text)
     
    Change the output side to this:
     
    HtmlHolder.InnerHtml = Server.HtmlDecode(TemplateString.ToString)
     
View as RSS news feed in XML