将 C# Web 应用程序更改为使用母版页后,DatePicker 不再工作
我正在开发一个 .Net/C# Web 应用程序,并一直使用基于 javascript 的日历来允许用户选择日期。这一直运作良好。
今天,我更改了代码以包含母版页,并且从子页面调用的日期选择器已停止工作,问题是返回日期的文本框不再有效,因为表单声明现在位于母版页。
代码是 href="javascript:;" onclick="calendarPicker('form1.TBApplyDate');" title="Select Date from Calendar">Select
"Error Line: 1 Error: 'window.opener.document.form1.TBApplyDate' is null or not an object"
我在网上看到了很多收集的例子文本框客户端 ID 并以下面的各种排列传递它,但我总是遇到相同的错误。
<代码> href="javascript:;" onclick="calendarPicker('ctl00_MainContent_TBApplyDate');" title="从日历中选择日期">选择
href="javascript:;" onclick="calendarPicker(form1.<%=TBApplyDate.ClientID%>');" title="从日历中选择日期">选择
任何人都可以提供有关如何成功引用文本框的任何帮助吗?
提前致谢。
I'm working on a .Net/C# web application and had been using a javascript based calendar to allow users to select dates. This has been working fine.
Today I changed the code to include a master page and the datepicker which is called from a childpage has stopped working, the problem being that the Textbox which the date is returned to is no longer valid, due to the fact the form declaration now sits on the master page.
The code ishref="javascript:;" onclick="calendarPicker('form1.TBApplyDate');" title="Select Date from Calendar">Select
"Error Line: 1 Error: 'window.opener.document.form1.TBApplyDate' is null or not an object"
I've seen plenty of examples online of collecting the textbox client ID and passing that in the various permutations below, but I always get the same error.
href="javascript:;" onclick="calendarPicker('ctl00_MainContent_TBApplyDate');" title="Select Date from Calendar">Select
href="javascript:;" onclick="calendarPicker(form1.<%=TBApplyDate.ClientID%>');" title="Select Date from Calendar">Select
Can anyone provide any help on how I can reference the textbox succesfully?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为元素 ID 被母版页“破坏”,
我建议使用 jQuery 及其选择器来帮助您获取必要的控件
在 jquery 中,您可以获取如下控件:
因此您应该能够执行此操作
编辑:
你也可以尝试这个
It is because element IDs get "mangled" by the Master Page
I would recommend using jQuery and its selectors to help you grab the necessary controls
In jquery you can grab a control like this:
Therefore you should be able to do this
Edit:
You can also try this
右键单击浏览器并查看源代码,并确保文本框的 ID 和 jQuery 例程中指定的 ID 相同。如果没有,请使用 @jmein 的答案来获取文本框的正确客户端 ID。
如果它们相同,则说明您的 jquery 设置方式有问题。
Right click on your browser and view source and make sure the ID of the textbox and the ID specified in your jQuery routine are the same. If not, use @jmein's answer to get the correct client id of the text box.
If they are the same, then there's something wrong with how you have your jquery setup.