I have a Textbox
added to an .ascx
control page as follows:
<asp:TextBox id="txtDescription" runat="server" Width="500" TextMode="MultiLine" Rows="2"></asp:TextBox>
And it would show something like this when first loaded (4 spaces at the start included):
Description goes here
Put simply, it's a Multiline Textbox
with 2 lines. However, whenever we do a Postback
to the server, when the page reloads, we get this:
Description goes here
Another Postback
.
Description goes here
And so on. Basically, every time the page is refreshed after a Postback
, it adds 4 spaces to the start of the textbox. On some pages, this isn't an issue, however, if the user is entering a fair bit of data into a Gridview
or some other Control
, the contents of the Textbox
can end up shunted 20 or so characters to the right, sometimes out of the bounds of the Textbox
.
Put simply, this is an issue for our company, as it is occurring across all of our pages. One of our clients has several times made a pass "...and could you do something about the spaces at the beginning of the textboxes at some point?"
Now, a temporary fix we have employed is the following code in our PageLoad
function, however, we are still left with 4 spaces at the beginning of the Textbox
. And rolling it out across 100's of .ascx
and .aspx
controls/pages isn't really a solution.
if (IsPostBack)
txtDescription.Text = txtDescription.Text;
Now the big question is, does anyone know how to remove these mysterious 4 spaces that keep getting added to the start of a Multiline Textbox
?
A typical html textarea (multiline textbox) looks like this:
<textarea>This is some content</textarea>
Now if your output looks like:
<textarea>
This is some content
</textarea>
Then you will introduce your space issue. When you save this content you gain the 4 spaces at the beginning (the indentation). Now you load those 4 spaces back and suddenly you have 8 spaces: 4 from the markup and 4 from the saved content. This pattern continues each time you save the content.
I am unfamiliar with how you (ASP Web Forms) are generating your content, but this should give you a point of investigation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With