displaying html code in a textbox control

Discussion in 'ASP .Net' started by Ned White, Apr 16, 2008.

  1. Ned White

    Ned White Guest

    Is it possible to insert HTML codes to a textbox control ?

    I am reading HTML formated string from sql server but if i assign this value
    to Text property of TextBox, the format tags of HTML seems too...

    sample string value from database:
    <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE: 11pt;
    mso-bidi-font-weight: bold">
    Sales Contract </SPAN></P>
    <SPAN style="FONT-SIZE: 11pt; mso-bidi-font-weight: bold">Paragraph 7.
    Buyer has the right to examine the goods upon receipt and has ____ days in
    which to notify seller of any claim for damages based on the condition,
    grade, quality or quality of the goods. Such notice must specify in detail
    the particulars of the claim. Failure to provide such notice within the
    requisite time period constitutes irrevocable acceptance of the goods.
    <o:p></o:p></SPAN></P>
    <P>&nbsp;</P>

    The string is asked for in a textbox because of the scrollbars of textbox,

    Are there any solutions to display html codes in textbox control or any
    suitable control for this ...?

    Thanks....
     
    Ned White, Apr 16, 2008
    #1
    1. Advertising

  2. Do Server.HtmlEncode before assigning this to the Text property....

    George.

    "Ned White" <nedwhite@> wrote in message
    news:...
    > Is it possible to insert HTML codes to a textbox control ?
    >
    > I am reading HTML formated string from sql server but if i assign this
    > value to Text property of TextBox, the format tags of HTML seems too...
    >
    > sample string value from database:
    > <P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN style="FONT-SIZE:
    > 11pt; mso-bidi-font-weight: bold">
    > Sales Contract </SPAN></P>
    > <SPAN style="FONT-SIZE: 11pt; mso-bidi-font-weight: bold">Paragraph 7.
    > Buyer has the right to examine the goods upon receipt and has ____ days in
    > which to notify seller of any claim for damages based on the condition,
    > grade, quality or quality of the goods. Such notice must specify in
    > detail the particulars of the claim. Failure to provide such notice
    > within the requisite time period constitutes irrevocable acceptance of the
    > goods. <o:p></o:p></SPAN></P>
    > <P>&nbsp;</P>
    >
    > The string is asked for in a textbox because of the scrollbars of textbox,
    >
    > Are there any solutions to display html codes in textbox control or any
    > suitable control for this ...?
    >
    > Thanks....
    >
     
    George Ter-Saakov, Apr 16, 2008
    #2
    1. Advertising

  3. Ned White

    Ned White Guest

    Hi George ,

    I am trying this.

    TextBox1.Text = Server.HtmlEncode(DT.Rows[0][1].ToString());

    But it seems in textbox like that:
    &lt;P class=MsoNormal style=&quot;MARGIN: 0cm 0cm
    0pt&quot;&gt;&lt;B&gt;&lt;SPAN \r\nstyle=&quot;FONT-SIZE:
    11pt&quot;&gt;Sales Contract &lt;?xml:namespace prefix = o ns =
    \r\n&quot;urn:schemas-microsoft-com:eek:ffice:eek:ffice&quot;
    /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;\r\n&lt;P
    class=MsoNormal style=&quot;MARGIN: 0cm 0cm 0pt&quot;&gt;&lt;B&gt;&lt;SPAN
    \r\nstyle=&quot;FONT-SIZE:
    11pt&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;\r\n

    but the value is :
    <P class=MsoNormal style=\"MARGIN: 0cm 0cm 0pt\"><B><SPAN
    \r\nstyle=\"FONT-SIZE: 11pt\">Sales Contract <?xml:namespace prefix = o ns =
    \r\n\"urn:schemas-microsoft-com:eek:ffice:eek:ffice\"
    /><o:p></o:p></SPAN></B></P>\r\n<P class=MsoNormal style=\"MARGIN: 0cm 0cm
    0pt\"><B><SPAN \r\nstyle=\"FONT-SIZE:
    11pt\"><o:p>&nbsp;</o:p></SPAN></B></P>\r\n
     
    Ned White, Apr 16, 2008
    #3
  4. Ned White

    Ned White Guest

    by the way, I forgot that it is a c# web project and i am trying this on a
    web form not a windows form.

    Sory for the mistake..
     
    Ned White, Apr 16, 2008
    #4
  5. On Apr 16, 9:39 am, "Ned White" <nedwhite@> wrote:
    > by the way, I forgot that it is a c# web project and i am trying this on a
    > web form not a windows form.
    >
    > Sory for the mistake..


    Hi,


    Good clarification :)

    Just a Label, instead. Or a Literal control
     
    Ignacio Machin ( .NET/ C# MVP ), Apr 16, 2008
    #5
  6. If you using WebControls then they will do Server.HtmlEncode automaticly.
    So TextBox1.Text = DT.Rows[0][1].ToString();
    That is why you end up encoding twice.. so <img> becomes &lt;img&gt; and
    then becomes &asmp;lt;img&amp;gt;

    If you using HtmlControsl they do not do that so you will need
    TextBox1.Value = Server.HtmlEncode( DT.Rows[0][1].ToString() );

    PS: I wish WebControls did not do encode too...

    George.

    "Ned White" <nedwhite@> wrote in message
    news:...
    > Hi George ,
    >
    > I am trying this.
    >
    > TextBox1.Text = Server.HtmlEncode(DT.Rows[0][1].ToString());
    >
    > But it seems in textbox like that:
    > &lt;P class=MsoNormal style=&quot;MARGIN: 0cm 0cm
    > 0pt&quot;&gt;&lt;B&gt;&lt;SPAN \r\nstyle=&quot;FONT-SIZE:
    > 11pt&quot;&gt;Sales Contract &lt;?xml:namespace prefix = o ns =
    > \r\n&quot;urn:schemas-microsoft-com:eek:ffice:eek:ffice&quot;
    > /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;\r\n&lt;P
    > class=MsoNormal style=&quot;MARGIN: 0cm 0cm 0pt&quot;&gt;&lt;B&gt;&lt;SPAN
    > \r\nstyle=&quot;FONT-SIZE:
    > 11pt&quot;&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;\r\n
    >
    > but the value is :
    > <P class=MsoNormal style=\"MARGIN: 0cm 0cm 0pt\"><B><SPAN
    > \r\nstyle=\"FONT-SIZE: 11pt\">Sales Contract <?xml:namespace prefix = o ns
    > = \r\n\"urn:schemas-microsoft-com:eek:ffice:eek:ffice\"
    > /><o:p></o:p></SPAN></B></P>\r\n<P class=MsoNormal style=\"MARGIN: 0cm 0cm
    > 0pt\"><B><SPAN \r\nstyle=\"FONT-SIZE:
    > 11pt\"><o:p>&nbsp;</o:p></SPAN></B></P>\r\n
    >
    >
    >
    >
     
    George Ter-Saakov, Apr 16, 2008
    #6
  7. Ned White

    Ned White Guest

    Thanks George,

    I use Panel control and <div> tag combination instead of textbox.

    the aspx code:
    <asp:panel ID="Panel1" runat="server" Width="100%" Height="100px"
    BorderStyle="Solid" BorderWidth="1px"
    ScrollBars="Auto" Style="padding:10px">
    <div id="ForTheDocs" runat="server">
    </div>
    </asp:panel>

    and the code-behind part:

    ForTheDocs.InnerHtml = Server.HtmlDecode(DT.Rows[0][1].ToString());


    Thanks a lot.
     
    Ned White, Apr 16, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. S. Justin Gengo
    Replies:
    0
    Views:
    553
    S. Justin Gengo
    Jul 16, 2003
  2. Hazzard
    Replies:
    2
    Views:
    569
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
  3. Natty Gur
    Replies:
    0
    Views:
    481
    Natty Gur
    Jul 22, 2003
  4. =?Utf-8?B?Q2hyaXM=?=
    Replies:
    3
    Views:
    13,834
    Peter Blum
    Mar 30, 2005
  5. Jay

    Rich TextBox / HTML TextBox

    Jay, Apr 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    15,718
    Steve C. Orr [MVP, MCSD]
    Apr 29, 2005
Loading...

Share This Page