简体   繁体   English

找不到Javascript更新的ASP.NET TextBox

[英]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. 该按钮将在弹出窗口中启动JavaScript日历。 That calendar returns a date into the ReservationDate textbox field using: 该日历使用以下命令将日期返回到ReservationDate文本框字段中:

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. 问题是,即使在浏览器上我在该字段中看到日期,当我单击“继续”按钮并尝试从.NET脚本访问该日期时,服务器端脚本也将其视为空。

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. 我认为您已将文本框设置为ReadOnly,这似乎是一个问题。 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. 如果在Page_Load中初始化该值,则该值将丢失。 I guess it must be something like that. 我想一定是那样的。

So you would write in your Page_Load: 因此,您可以在Page_Load中编写:

if(!Page.IsPostBack)
{
Initialize();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM