【问题标题】:Custom control with jquery, what to do next?用jquery自定义控件,下一步怎么办?
【发布时间】: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


    【解决方案1】:

    原来回发迫使页面再次生成 ChildControls,但没有 ModalViewID,它没有存储在我的自定义控件的 Viewstate 中,因此生成“小马”jquery!为了解决这个问题,我在我的创建子控件方法上添加了一个简单的检查,如果 modalviewid == null 或为空,我也可以将我的 modalViewID 分配给 viewstate。

    还是谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多