ASP.NET 显示来自代码隐藏中创建的按钮的 ModalPopupExtender
您好,我的 aspx 网页中有一个 modalPopupExtender 指向一个面板,在代码隐藏中我创建了按钮,我希望它们显示 modalPopup,所以我有:
buttonX.OnClientClick = "javascript:$get(" + modalPopup.ClientID + ").show();";
但它只是执行 PostBack,即使我输入“return false” ;”在过去代码的末尾。
Hi I have a modalPopupExtender in my aspx web page pointing to a Panel and in Code-Behind I create buttons which I want them to show the modalPopup, so I have:
buttonX.OnClientClick = "javascript:$get(" + modalPopup.ClientID + ").show();";
but instead it just does a PostBack, even if I put "return false;" at the end of the past code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想我已经找到了一些办法,尽管我不确定这是最好的解决方案。
这是我的代码隐藏:
这是我的 ASPX 页面:
这使得模式弹出而不回发=D!
I think I have figured something out although I'm not sure it's the best solution.
This is my code-behind:
and this is my ASPX page:
And this makes the modal pop up without posting back =D!
试试这个
Try this
我想我看到了你的问题。您没有在 JS 调用中引用 ClientID,因此它实际上只是失败 - 这就是
return false
也不起作用的原因。如果唯一的问题是回发,您仍然应该在页面回发到自身之前看到弹出窗口。您的代码:
将添加
"javascript:$get(ctl123).show();"
(我使用 ctl123 作为您的 ClientID 的占位符名称) - 这个想法是错误正在发生因为你应该有这样的:它将输出
"javascript:$get('ctl123').show();"
区别在于第二个中控件 ID 被引用。
尝试一下,并添加
return false;
以防止回发。就像这样:I think I see your problem. You aren't quoting the ClientID in your JS call, so it's actually just failing - that's why
return false
isn't working either. If the only issue was the postback you should still see your popup before the page posts back to itself.Your code:
Will add
"javascript:$get(ctl123).show();"
(I'm using ctl123 as a placeholder name for whatever your ClientID is) - the idea is the error is happening because what you should have is this:Which will output
"javascript:$get('ctl123').show();"
The difference being that in the second one the control ID is quoted.
Give that a try, and add
return false;
to prevent the postback. Like so: