【发布时间】:2012-02-17 05:57:30
【问题描述】:
我目前正在开发一个 Web 应用程序并创建一些自定义控件。我创建了一个自定义“模态按钮”,它继承自 Web 控件和 INamingContainer,该控件使用嵌入式资源来注册客户端代码(FancyBox jQuery),模态按钮在模态中显示一个 Iframe,并且在我的Default.aspx 页面。
问题:
我试图在另一个页面上声明另一个“模态按钮”控件,但是模态弹出窗口无法回发。我研究了这个错误,发现这个页面上没有生成 _DoPostBack。因此我添加了方法:this.Page.ClientScript.GetPostBackClientHyperlink(this, "");。这会生成 _doPostBack 函数并导致回发,但是第二次无法打开模态!
这是我在自定义控件方法中生成的客户端脚本覆盖 CreateChildControls():
// http://fancybox.net/
StringBuilder jQueryInclude = new StringBuilder();
jQueryInclude.Append("$(document).ready(function () { ");
// Uses ".class" selector
jQueryInclude.AppendFormat("$('.{0}').fancybox( ", this.ModalViewID);
jQueryInclude.Append(" { ");
jQueryInclude.Append(" 'titlePosition': 'outside',");
jQueryInclude.Append(" 'modal': 'true', ");
jQueryInclude.Append(" 'transitionIn': 'elastic', ");
jQueryInclude.Append(" 'transitionOut': 'fade', ");
jQueryInclude.Append(" }); ");
jQueryInclude.Append("});");
var closeMethod = String.Format("{0}_CloseDialog()", close.ClientID);
jQueryInclude.Append(" function METHOD_NAME { ").Replace("METHOD_NAME", closeMethod);
jQueryInclude.Append(" $.fancybox.close(); ");
jQueryInclude.AppendFormat(" __doPostBack('<%= {0} %>', '' )", close.ClientID); // Postback on close to reload iframe
jQueryInclude.Append(" } ");
close.OnClientClick = closeMethod;
//user preference else all modals will be same
Page.ClientScript.RegisterClientScriptBlock(typeof(ModalButton), String.Format("{0}_fancyBox", this.ModalViewID), jQueryInclude.ToString(), true);
我需要知道的:
如何确保这个自定义的“模态按钮”生成_DoPostBack 函数并在它被回发时再次打开。
提前致谢
【问题讨论】:
标签: c# jquery asp.net custom-controls fancybox