ASP.NET TextBox updated by Javascript not seen
This is going to be easy for someone who knows what they are doing.
I have a launch calendar button, a continue button, and a date textbox. The button launches a JavaScript calendar in a popup window. That calendar returns a date into the ReservationDate textbox field using:
window.opener.document.getElementById('ctl00_wpm_ShowProduct_ctl10_ReservationDate').value =开发者_运维百科 '<%= CurrentDate %>';
I know, it's not elegant but works. The problem is that even though on the browser I see the date in the field, when I hit the continue button and try to access it from my .NET script, the server side script sees it as empty.
How do I tell the server to use the text the browser has in that field that it is not seeing?
I know enough to know that it's a server side versus client side issue but how do I bridge that gap?
I think you have set your textbox as ReadOnly and that seems to be an issue. Set it readonly like this in code behind:
TextBox1.Attributes.Add("readonly", "readonly");
Check this.
If you initialize the value in the Page_Load, the value will get lost. I guess it must be something like that.
So you would write in your Page_Load:
if(!Page.IsPostBack)
{
Initialize();
}
精彩评论