When I click submit the insert fails, if I change the visible value to "true" the insert succeeds.
I know this is probably really simple but I can't figure it out.If you set a controls visibility to false then it doesn't appear in the rendered HTML, therefore your hidden field won't be there at all (check the HTML source). In order to make a control still contain a value but be readonly try using the enabled property and set it to fale instead eg
<asp:TextBox id="myTextBox" enabled="false" runat="server"/>
That way the value is retained but it can't be changed.
Other option is to use a 'traditional' <input type="hidden"> field.
Thanks but the value has to be editable. The hidden field is actually receiving a date that is selected from a calendar on the page using this:
void Selection_Change(Object sender, EventArgs e)
{
countDate.Text = calendar.SelectedDate.ToShortDateString();
}
Where countDate is the hidden field.
If there is an easier way to do this please let me know.
As was explained,
you could use:
<input type="hidden"runat="server" ID="countDate"
Then just the code would be:
countDate.Value = calendar.SelectedDate.ToShortDateString();
Thanks, that worked.
I now have another problem, when changing the date on the calendar it appears to be trying to submit the form, causing error messages as some other fields are also required.
0 comments:
Post a Comment