tags:

views:

1440

answers:

4

hi guys, 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?

+6  A: 

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

Darin Dimitrov
Very good catch! +1
Cerebrus
darin, is readonly supported by all the common browsers? Didn't know about this attribute.
nickyt
A: 

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.

nickyt
A: 

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;
A: 

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");

George