使用ModalPopupExtender无需设置TargetControlID?
我想在我的 asp.net 页面中使用 modalpopupextender 来显示子表单。但它只需要在特定条件下才会显示。这些条件是由一段 JavaScript 代码确定的。
因此,最重要的是,模式弹出窗口不必在单击按钮时显示。但是,如果我将属性 TargetControlID 留空,则会出现以下异常:
“ModalPopupExtender1”的 TargetControlID 无效。该值不能为 null 或为空。 描述:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息: System.InvalidOperationException: 目标控件ID 'ModalPopupExtender1' 是 无效。该值不能为空或 空。
我是否只有 TargetControlID 到隐藏按钮还是还有更合适的选择?
I'd like to use a modalpopupextender in my asp.net page to show a sub form. But it only has to show on specific conditions. Those conditions are determined in a piece of javascript code.
So, most importantly, the modal popup doesn't have to show on a button click. However, if I leave the property TargetControlID empty I get the following exception:
The TargetControlID of 'ModalPopupExtender1' is not valid. The value cannot be null or empty.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details:
System.InvalidOperationException: The
TargetControlID of
'ModalPopupExtender1' is
not valid. The value cannot be null or
empty.
Do I just have the TargetControlID to an hidden button or is there aslo a more decent option?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我所知,将 TargetControlID 设置为隐藏按钮(display:none;)是最好的方法。
Setting the TargetControlID to a hidden button(display:none;) is the best way as far as I know.
TargetControlID 还可以设置为 HiddenField 类型。这样你甚至不需要一个按钮
The TargetControlID could also be set to a HiddenField type. That way you don't even need a button
创建一个按钮并将其设置为 TargetControlId 并指定
style = "display:none"
Crete a button and set it as your TargetControlId and give
style = "display:none"