This is a migrated thread and some comments may be shown as answers.

Readonly Textbox clearing on postback

6 Answers 411 Views
Input
This is a migrated thread and some comments may be shown as answers.
Omlac
Top achievements
Rank 1
Omlac asked on 19 Nov 2008, 12:32 PM
Hi all
im trying to add a readonly textbox on my form but the problem is it keeps clearing the textbox on postback, if i remove the read only property it works fine.

Does anyone know whats causing this.

6 Answers, 1 is accepted

Sort by
0
Missing User
answered on 19 Nov 2008, 02:13 PM
Hello Omlac,


The Text value of the RadTextBox control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box. This prevents a malicious user from changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code.

Greetings,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Omlac
Top achievements
Rank 1
answered on 24 Nov 2008, 06:16 AM
Thank you very much for your response,
Does that mean i cant use a readonly Textbox when i want to keep the value displayed, suprisingly though i have another textbox on the same form whick keeps its value even after postback.

Regards
0
Accepted
Missing User
answered on 27 Nov 2008, 11:05 AM
Hello Omlac,

As explained in this help article you cannot change the Text value of the RadInput control when its ReadOnly property is set to "true". In short, if you intend to modify the value of the control you should not use ReadOnly. If you want to be able to change the Text value (via client or server code) and at the same time prevent the user from doing so, you can use the Enabled="false" property. I hope this helps.

Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ubirajara
Top achievements
Rank 1
answered on 10 Nov 2011, 08:01 PM
Hi, Im mexican, i had the same problem, the solution is..

add in the event Page_Load in the codebehind file
protected void Page_Load(object sender, EventArgs e)
        {
            textboxId.Attributes.Add("readonly", "true");
        }

that works funny
0
Francis
Top achievements
Rank 1
answered on 14 Jun 2012, 02:26 PM
Hi, I have almost the same problem.

I have a RadTextBox control with Enabled="false". I change his value in Javascript. Then a PostBack occurs (after a change in a cutom AutoComplete control), the original value is displayed in the TextBox.

I have PageLoad event, but all the code is in a if(!IsPostBack) test...

Any idea ?


PS: version 2012.1.411.40
0
Vasil
Telerik team
answered on 15 Jun 2012, 01:07 PM
Hello Francis,

When RadTextBox is disabled (Enabled="false") the text can not be changed client side by the user. Even if you change it using JavaScript or editing the DOM using some developer tools, the changes will not reflect to server side values.

Regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Input
Asked by
Omlac
Top achievements
Rank 1
Answers by
Missing User
Omlac
Top achievements
Rank 1
Ubirajara
Top achievements
Rank 1
Francis
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or