Click here to Skip to main content
16,013,465 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to display an exact format of string or words in textbox?.



this is my code below.

when i write:

"hello world this
this is a test article".

I expect that what i write should display in that format.but what happen is that in display txtArticles it display continous like this.

"hello world this is a test article".


<
XML
<div style="margin-left:200px; width: 756px;">
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Label ID="lblNewsFeed" runat="server" Text="News Feed:" Font-Bold="True"
                Font-Size="Larger" ForeColor="White" style="font-size: 35pt" Width="240px"
                Font-Italic="True"></asp:Label>
            <br />
            <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Image ID="imgNewsFeed" runat="server" Height="102px" Width="116px"  /> <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:FileUpload ID="FileUploadNewsFeed" runat="server" ForeColor="White" />
            <br />
            <br />
            <asp:Label ID="lblTitle" runat="server" Text="Title:" Font-Bold="True"
                Font-Italic="False" ForeColor="White" style="font-size: 15pt"></asp:Label> <br />
            <asp:TextBox ID="txtTitle" runat="server" Width="570px"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please Write the Title!" Font-Bold="True" Font-Size="15pt" ForeColor="#FFFF99" style="font-size: 13pt" ControlToValidate="txtTitle" ></asp:RequiredFieldValidator>
            <br />
            <br />
            <asp:Label ID="lblArticles" runat="server" Text="Articles:" Font-Bold="True"
                ForeColor="White" style="font-size: 15pt"></asp:Label> &nbsp;&nbsp;&nbsp;<asp:Label ID="lbl_Save" runat="server" Font-Bold="True" Font-Size="15pt" ForeColor="#FFFF99" ></asp:Label>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please Write the Article!" Font-Bold="True" Font-Size="15pt" ForeColor="#FFFF99" style="font-size: 13pt" ControlToValidate="txtArticles" ></asp:RequiredFieldValidator>
            <br />
            <asp:TextBox ID="txtArticles" runat="server" TextMode="MultiLine" Wrap="true"
                Height="350px" Width="570px" CssClass="NoresizeTextBox" ></asp:TextBox> <br />
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <asp:Button ID="btnClear" runat="server" Text="Clear"
                BackColor="#669999" BorderColor="#009999" Font-Bold="True" Font-Italic="False"
                ForeColor="White" OnClick="Clear_Click" CausesValidation="False" />

            &nbsp;&nbsp;&nbsp;<asp:Button ID="btnPost" runat="server" Text="Post Article"
                BackColor="#669999" BorderColor="#009999" Font-Bold="True" Font-Italic="False"
                ForeColor="White" OnClick="ArticlePost_Click"/>

        </div>

>




C#
<<pre lang="xml">asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
                        <HeaderTemplate >
                            <table style="border-left-color:#75A4A4; border-left-style: solid; border-left-width: 2.5px;  border-top-style: solid; border-top-width: 2.5px; border-top-color:#75A4A4;" width="570" >
                        </HeaderTemplate>

                        <ItemTemplate>
                        <tr style="border-right-color:#669999">
                            <td>
                            <asp:Label ID="lblDate" runat="server" style="border-bottom-color :#719F9F; border-bottom-style: solid; border-bottom-width: 2.5px;"  Font-Size="11" Font-Bold="true" ForeColor="white" TextMode="MultiLine" Rows="0" Enabled="False" ReadOnly="True" BackColor="#669999" Wrap="True" Height="18px" Width="570px" BorderWidth="0px"  Text='<%#Eval("Date") %>' /> <br />
                            <asp:Label ID="lblTime" runat="server" style="border-bottom-color :#719F9F; border-bottom-style: solid; border-bottom-width: 2.5px;"  Font-Size="11" Font-Bold="true" ForeColor="white" TextMode="MultiLine" Rows="0" Enabled="False" ReadOnly="True" BackColor="#669999" Wrap="True" Height="18px" Width="570px" BorderWidth="0px"  Text='<%#Eval("Time") %>'/> <br /> <br /> <br />
                            <asp:TextBox ID="txtTitle" runat="server" Font-Names="Times New Roman" Font-Size="25px" ForeColor="white" Font-Bold="true" Rows="0" TextMode="MultiLine" Enabled="False" ReadOnly="True" BackColor="#669999" Wrap="True" Height="70px" Width="570px" BorderWidth="0px" style="text-align:center" CssClass="NoresizeTextBox" Text='<%#Eval("Title") %>'/> <br />
                            <asp:ImageButton ID="ImageButton1" runat="server" BackColor="#669999" ImageUrl='<%#Eval("ImageName", "~/NewsFeedImages/{0}") %>' Height="150px" Width="150px" style="margin-left:210px; cursor:pointer"  OnClientClick="return LoadDiv(this.src);" Title="View Image"  />
                            </td>

                        </tr>

                        <tr style="border-right-color:#669999;" >
                            <td class=" comment more"  <asp:TextBox ID="txtArticle" runat="server" style="text-align:left;" ForeColor="white" Font-Size="13"  Wrap="true" TextMode="MultiLine" Enabled="true" ReadOnly="True" BackColor="#669999" Width="570px" Height="100px" BorderWidth="0px"  CssClass="NoresizeTextBox"  Text='<%#DataBinder.Eval(Container.DataItem,"Articles").ToString() %>'></asp:TextBox>
                            </td>
                        </tr>

                        <tr>
                            <td style="border-bottom-style: solid; border-bottom-width:2px; border-bottom-color: #75A4A4;">
                            <br />
                            </td>
                        </tr>
                        </ItemTemplate>

                        <FooterTemplate>
                            </table>
                        </FooterTemplate>
                    </asp:Repeater>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                        ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString25 %>"
                        SelectCommand="SELECT [Title], [Articles], [Date], [Time], [ImageName] FROM [NewsFeedTbl] ORDER BY [id] DESC">
                    </asp:SqlDataSource

>
Posted

1 solution

Dear god what is with all the &nbsp; 's (btw none of that code is relevant from what i can tell), since this is HTML in order to do a line break you need to add


"hello world this
this is a test article".


To get this format to look like this in HTML you would do
"hello world this <br />
this is a test article".


Tah dah

However you specifically say "Textbox". In html, a textbox (input type="text") is a single line input, I think what you are looking for is a text area.

XML
<textarea style="width:400;">
 "hello world this
this is a test article".

 </textarea>



By using a text area you could simply type your content in as is and it would show as desired.

Or you could use the <pre> element as well.

XML
<pre>
 "hello world this
this is a test article".
 
</pre>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900