Showing posts with label asptextbox. Show all posts
Showing posts with label asptextbox. Show all posts

Monday, March 26, 2012

Text in asp:TextBox

I'm having some trouble with my Asp:TextBox (a multiline actually). I want to write some text in it, so I use the expression "NameOfTextBox.Text='Some text'". Unfortunatly 'Some text' is converted to HTML (for example: < is automaticly converted to &lt;).

I want to take care of any html-conversion myself. Is there a way to tell the textbox, that I want it to contain the the text without modifications?I'm not understanding where the conversion is taking place. I have a simple page below that loads a string into textbox and shows it as I've set it. Of course, it's impossible to actuallyshow that in this forum (grrr), but basically I'm setting the text to "< b >Hello< /b >" (no spaces in the tags. It shows the < and > characters in the text box. Is that what you mean?

<%@. Page Language="VB" %>
<script runat="server">
Sub Page_Load()
textbox1.text = "Hello "
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</form>
</body>
</html>

I will make myself a bit clearer. If I use the code-line:

textbox1.text = "<"

I want the HTML generated to be something like this:

<textbox id=textbox1><</textbox>

As it is now, the result will be:

<textbox id=textbox1><</textbox>

The text is in some way automatically encoded to be displayed as proper HTML. I have problem, 'cause I use Swedish characters as ö and that is automatically encoded to &ouml;. See my problem?
The encoding of < into < in a textbox is normal and conforms to the HTML standard AFAIK.
The TextBox control automatically encodes the text. To get the proper ö, just set the text to a normal string with the special character to avoid double encoding:
simply writing textbox1.Text = "ö" will produce the desired character.

Does this help?
It works with writing just textbox1.Text = "ö", but the problem is that the text to be displayed is already encoded. The text is taken from a file, which has all its text in HTML-format. If there is no way to tell the textbox to display the proper text, is there a way to decode the html into text again (make ö into ö and so on)? If not, I think there are some other (complicated) ways to solve it.
You can try HttpUtility.HtmlDecode.
HttpUtility.HtmlDecode may be what I'm looking for. Thanks.

Saturday, March 24, 2012

Text manipulation

Hi

Can someone please help me!? I'm trying to work out how to take text from a multiline asp:TextBox and find and replace the \r\n characters with equivalent HTML <p></p> tags. So that when it is retrieved from the database it can be displayed as correct HTML!

I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.

Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!

Please can someone point me in the right direction!

Many thanks

Ross

Hey Dude!

Did you try this:

string.Replace("\r\n","<br/>") ?


kcis8rm:

I'm not sure where to start really. I thought that if I did a replace on \r\n\r\n (I think thats what shows a paragraph) with </p><p> that would work. However that wouldn't pick up the beginning of the string, and would add a <p> tag at the end that would fail validation.

Also the reverse is true, if I wanted to put the text back into a textbox for editing, I wouldn't want the HTML to show?!

You would be better off using one of the free rich text editors. Otherwise \r\r should find a paragraph break, then you would have to manipulate the result of your Replace() operation to add <p> to the beginning, and remove <p> at the end.




Dude

Check this out, I just figured that link for you: http://www.phptr.com/articles/article.asp?p=29585&rl=1

may be it gonna help you to solve your problem, try it out and let me know if it works, else paste your code and we will work on it together.


Hi

Thanks for the help, I think I've now sorted it :-)


I've now sorted this, however you brought up and interesting point! Can you point me in the direction of some of these free rich text editors please?!

kcis8rm:

Hi

Thanks for the help, I think I've now sorted it :-)

Good. What did you do? It might be of interest to others who find this thread.


I solved it by using a regular expression to replace the pattern \r\n\r\n (which shows a paragraph) with the text </p><p> and then adding a <p> to the beginning of the string and a </p> to the end of the string!


Excellent. Any chance of marking my post as the answer then?Wink

Tuesday, March 13, 2012

TextBox and TextChanged event

I have an asp:TextBox on my page and I've set the OnChange attribute and implemented the TextChanged event handler and it works fine most of the time.

However, if I clear the contents of the text box and then start entering a new value, and I get a drop down list of recently entered values starting with the same letters that I've just entered in the textbox, and I then select one of items from the drop down list the TextChanged event doesn't fire.

Anyway to get around this? Disable the drop down list from ever appearing?

Thanks
Jonyou prbly have autofill on...go to tools -> internet options -> content in your browser and uncheck the autofill properties...

hth

TextBox AutoPostBack=false question (bug?)

Hello,
I have a strange yet very simple problem with the asp.net Textbox web contro
l.
On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.
according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).
Now if i add another textbox to the page, i no longer experience the
problem(''?).
Is my framework (2.0) corrupted or is anyone else able to reproduce that bug
?
Thanks for any help
Renaud
=============
sample page
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"
></asp:TextBox>
</form>
</body>
</html>Apparently this is the default behavior of an ASP.NET page with only one
textbox on it. For example if there were a page that had a search textbox an
d
no button to submit the search, you could type in a search term and hit the
ENTER key and the form would be submitted.
There are lots of techniques and new features in ASP.NET 2.0 that let you
customize this type of behavior, such as the "defaultbutton" property of the
FORM element.
But the bottom line is, there's nothing wrong with your Framework - that's
just "the way it is".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:

> Hello,
> I have a strange yet very simple problem with the asp.net Textbox web cont
rol.
> On an empty asp.net page, add a single asp:TextBox control with
> Autopostback=false with nothing else on the page.
> according to the doc, hitting Enter while the TextBox has focus should do
> nothing since Autopostback=false. The problem i have is that it posts the
> form (that is, it ignores the Autopostback=false).
> Now if i add another textbox to the page, i no longer experience the
> problem(''?).
> Is my framework (2.0) corrupted or is anyone else able to reproduce that b
ug?
> Thanks for any help
> Renaud
> =============
> sample page
> <%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
> Inherits="_Default" %>
> <html>
> <body>
> <form id="form1" runat="server">
> <asp:TextBox runat="server" ID="txt" AutoPostBack="false"
> </form>
> </body>
> </html>
The main problem with this behavior is that it bypasses the control
validations.
If the textbox is a TextBoxValidator, hitting the enter key posts the form
even if the textbox content breaks the validation rules. Validations are
performed correctly on the server side but it's still a useless roundtrip to
the server.
I suppose this could be corrected by using a button on the page. The problem
is, in our application, buttons are replaced by LinkButtons.
Thanks for your quick answer.
Renaud
"Peter Bromberg [C# MVP]" wrote:
> Apparently this is the default behavior of an ASP.NET page with only one
> textbox on it. For example if there were a page that had a search textbox
and
> no button to submit the search, you could type in a search term and hit th
e
> ENTER key and the form would be submitted.
> There are lots of techniques and new features in ASP.NET 2.0 that let you
> customize this type of behavior, such as the "defaultbutton" property of t
he
> FORM element.
> But the bottom line is, there's nothing wrong with your Framework - that's
> just "the way it is".
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "Renaud Langis" wrote:
>
Have you tried something like adding another Textbox to your page, and
setting its width property to zero?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:
> The main problem with this behavior is that it bypasses the control
> validations.
> If the textbox is a TextBoxValidator, hitting the enter key posts the form
> even if the textbox content breaks the validation rules. Validations are
> performed correctly on the server side but it's still a useless roundtrip
to
> the server.
> I suppose this could be corrected by using a button on the page. The probl
em
> is, in our application, buttons are replaced by LinkButtons.
> Thanks for your quick answer.
> Renaud
> "Peter Bromberg [C# MVP]" wrote:
>
Yes, i solved it by adding a TextBox with display:none
It's not nice but it works...
Thanks
Renaud
"Peter Bromberg [C# MVP]" wrote:
> Have you tried something like adding another Textbox to your page, and
> setting its width property to zero?
> Peter
> --
> Site: http://www.eggheadcafe.com
> UnBlog: http://petesbloggerama.blogspot.com
> Short urls & more: http://ittyurl.net
>
>
> "Renaud Langis" wrote:
>

TextBox AutoPostBack=false question (bug?)

Hello,

I have a strange yet very simple problem with the asp.net Textbox web control.

On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.

according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).

Now if i add another textbox to the page, i no longer experience the
problem(?????).

Is my framework (2.0) corrupted or is anyone else able to reproduce that bug?

Thanks for any help

Renaud

=============
sample page
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"

Quote:

Originally Posted by

></asp:TextBox>


</form>
</body>
</html>Apparently this is the default behavior of an ASP.NET page with only one
textbox on it. For example if there were a page that had a search textbox and
no button to submit the search, you could type in a search term and hit the
ENTER key and the form would be submitted.

There are lots of techniques and new features in ASP.NET 2.0 that let you
customize this type of behavior, such as the "defaultbutton" property of the
FORM element.

But the bottom line is, there's nothing wrong with your Framework - that's
just "the way it is".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:

Quote:

Originally Posted by

Hello,
>
I have a strange yet very simple problem with the asp.net Textbox web control.
>
On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.
>
according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).
>
Now if i add another textbox to the page, i no longer experience the
problem(?????).
>
Is my framework (2.0) corrupted or is anyone else able to reproduce that bug?
>
Thanks for any help
>
Renaud
>
=============
sample page
<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"

Quote:

Originally Posted by

</asp:TextBox>


</form>
</body>
</html>


The main problem with this behavior is that it bypasses the control
validations.
If the textbox is a TextBoxValidator, hitting the enter key posts the form
even if the textbox content breaks the validation rules. Validations are
performed correctly on the server side but it's still a useless roundtrip to
the server.

I suppose this could be corrected by using a button on the page. The problem
is, in our application, buttons are replaced by LinkButtons.

Thanks for your quick answer.

Renaud

"Peter Bromberg [C# MVP]" wrote:

Quote:

Originally Posted by

Apparently this is the default behavior of an ASP.NET page with only one
textbox on it. For example if there were a page that had a search textbox and
no button to submit the search, you could type in a search term and hit the
ENTER key and the form would be submitted.
>
There are lots of techniques and new features in ASP.NET 2.0 that let you
customize this type of behavior, such as the "defaultbutton" property of the
FORM element.
>
But the bottom line is, there's nothing wrong with your Framework - that's
just "the way it is".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Renaud Langis" wrote:
>

Quote:

Originally Posted by

Hello,

I have a strange yet very simple problem with the asp.net Textbox web control.

On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.

according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).

Now if i add another textbox to the page, i no longer experience the
problem(?????).

Is my framework (2.0) corrupted or is anyone else able to reproduce that bug?

Thanks for any help

Renaud

=============
sample page
<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"

Quote:

Originally Posted by

></asp:TextBox>


</form>
</body>
</html>


Have you tried something like adding another Textbox to your page, and
setting its width property to zero?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:

Quote:

Originally Posted by

The main problem with this behavior is that it bypasses the control
validations.
If the textbox is a TextBoxValidator, hitting the enter key posts the form
even if the textbox content breaks the validation rules. Validations are
performed correctly on the server side but it's still a useless roundtrip to
the server.
>
I suppose this could be corrected by using a button on the page. The problem
is, in our application, buttons are replaced by LinkButtons.
>
Thanks for your quick answer.
>
Renaud
>
"Peter Bromberg [C# MVP]" wrote:
>

Quote:

Originally Posted by

Apparently this is the default behavior of an ASP.NET page with only one
textbox on it. For example if there were a page that had a search textbox and
no button to submit the search, you could type in a search term and hit the
ENTER key and the form would be submitted.

There are lots of techniques and new features in ASP.NET 2.0 that let you
customize this type of behavior, such as the "defaultbutton" property of the
FORM element.

But the bottom line is, there's nothing wrong with your Framework - that's
just "the way it is".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
"Renaud Langis" wrote:

Quote:

Originally Posted by

Hello,
>
I have a strange yet very simple problem with the asp.net Textbox web control.
>
On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.
>
according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).
>
Now if i add another textbox to the page, i no longer experience the
problem(?????).
>
Is my framework (2.0) corrupted or is anyone else able to reproduce that bug?
>
Thanks for any help
>
Renaud
>
=============
sample page
<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"
</asp:TextBox>
</form>
</body>
</html>


Yes, i solved it by adding a TextBox with display:none

It's not nice but it works...

Thanks

Renaud

"Peter Bromberg [C# MVP]" wrote:

Quote:

Originally Posted by

Have you tried something like adding another Textbox to your page, and
setting its width property to zero?
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Renaud Langis" wrote:
>

Quote:

Originally Posted by

The main problem with this behavior is that it bypasses the control
validations.
If the textbox is a TextBoxValidator, hitting the enter key posts the form
even if the textbox content breaks the validation rules. Validations are
performed correctly on the server side but it's still a useless roundtrip to
the server.

I suppose this could be corrected by using a button on the page. The problem
is, in our application, buttons are replaced by LinkButtons.

Thanks for your quick answer.

Renaud

"Peter Bromberg [C# MVP]" wrote:

Quote:

Originally Posted by

Apparently this is the default behavior of an ASP.NET page with only one
textbox on it. For example if there were a page that had a search textbox and
no button to submit the search, you could type in a search term and hit the
ENTER key and the form would be submitted.
>
There are lots of techniques and new features in ASP.NET 2.0 that let you
customize this type of behavior, such as the "defaultbutton" property of the
FORM element.
>
But the bottom line is, there's nothing wrong with your Framework - that's
just "the way it is".
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net
>
>
>
>
"Renaud Langis" wrote:
>
Hello,

I have a strange yet very simple problem with the asp.net Textbox web control.

On an empty asp.net page, add a single asp:TextBox control with
Autopostback=false with nothing else on the page.

according to the doc, hitting Enter while the TextBox has focus should do
nothing since Autopostback=false. The problem i have is that it posts the
form (that is, it ignores the Autopostback=false).

Now if i add another textbox to the page, i no longer experience the
problem(?????).

Is my framework (2.0) corrupted or is anyone else able to reproduce that bug?

Thanks for any help

Renaud

=============
sample page
<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb"
Inherits="_Default" %>
<html>
<body>
<form id="form1" runat="server">
<asp:TextBox runat="server" ID="txt" AutoPostBack="false"
></asp:TextBox>
</form>
</body>
</html>