user42348
user42348

Reputation: 4319

How to get value in a textbox that is readonly

I have a textbox.In its onclick iam calling a javascript fn to call calendar.Texbox is readonly. Clicking on textbox calendar is coming and value is showing in textbox. But on clicking submit button where I have written code to save, there i am not getting value in textbox. What may be the reason for that?

Upvotes: 0

Views: 14660

Answers (5)

Hari Prasad Kotha
Hari Prasad Kotha

Reputation: 66

You can get the value by using

Request.Form[YourTextBox.UniqueID]

Upvotes: 2

George
George

Reputation: 163

I had this problem too, there is a really simple workaround

Instead of making the textbox ReadOnly using properties option. Do it thru the code behind adding this code:

YourTextBox.Attributes.Add("readonly", "readonly");

Upvotes: 6

spielersun
spielersun

Reputation:

if readonly property is true, its not break your .cs call. you can use this as always:

here are your inputs:

<asp:TextBox ID="txtBraid" runat="server" Text="Im sooo readonly" ReadOnly="True"></asp:TextBox>
<asp:Label ID="lblBraid" runat="server" Text="Im gonna change, i promise"></asp:Label>

on .cs page put these to onClick function or something:

lblBraid.Text = txtBraid.Text;

Upvotes: 0

nickytonline
nickytonline

Reputation: 6981

I'm guessing the textbox is disabled so that people have to use the calendar control to enter a date? The textbox is just for showing the selected date?

If you want the textbox to stay readonly (i.e. disabled client-side), have a hidden input that has the value you want to handle on the server is the way to go probably. So add an additional input for to the page. Use

<asp:HiddenField ... runat="server" />

So the client-side code that updates your readonly textbox will also update your hidden input.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039278

I suspect that your text box has the disabled attribute instead of readonly which prevents it from posting its value to the server.

Upvotes: 7

Related Questions