0

アプリケーションの 1 つで jquery color box を呼び出しています。開くことはできますが、カラーボックスを同時に開いているときに、ページを最初にポストバックしたいです。以下のコードを試しました。

aspx:

<script type="text/javascript">
        function OpenColorBox() {
            $.colorbox({
                opacity: 0.1,
                width: '350px',
                height: '350px',
                iframe: true,
                href: '/MMP/MMPhome.aspx',
                onLoad: function () {

                    $('#cboxClose').remove();
                },
                onClosed: function () {

                }
            });
        }

    </script>

<asp:Button ID="Call" runat="server" Text="Save this Search Criteria" 
                    OnClientClick="OpenColorBox(); return false;" onclick="Call_Click" />

ポップアップを開いていますが、最初に自分のページをポストバックしたいです。誰かが方法を知っているなら、私を助けてください。

4

2 に答える 2

1

ポストバックを発生させる必要がある場合は、ColorBox を開いて、次の操作を実行できます。

ASCX:

<asp:Button ID="Call" runat="server" Text="Save this Search Criteria" 
                    onclick="Call_Click" />

コードビハインド:

private void Call_Click(object sender, EventArgs e)
{
   Page.ClientScript.RegisterClientStartupScript(this.GetType(), "OpenColorBoxAfterClick", "OpenColorBox();", true);
   //Handle the rest of your code
}

ColorBox を開くときにポストバックが必要な場合は、Ajax を使用する必要があります。ボタンを含む UpdatePanel は、トリックを行います。

ASCX:

分離コード:

private void Call_Click(object sender, EventArgs e)
{
   //Handle click as normal
}

UpdatePanel を使用する必要があるが、updatepanel が返された後にも JavaScript を呼び出す場合:

ASCX:

<asp:Button ID="Call" runat="server" Text="Save this Search Criteria" 
                    onclick="Call_Click" />

コードビハインド

private void Call_Click(object sender, EventArgs e)
{
   ScriptManager.RegisterStartupScript(this, this.GetType(), "OpenColorBoxAfterClick", "OpenColorBox();", true);
   //Handle click as normal
} 
于 2012-07-19T16:37:29.353 に答える
1

You are not able to call the button click event because colorbox renders the div which is shown to the user outside the form on the page. To over come this problem you have to a small change in the plugin.

Look for the appendHTML() function in the colorbox plugin and replace the below lines:

if (!$box && document.body)

with:

if (!$box && document.forms[0])

In the last line of the method, replace:

$(document.body).append($overlay, $box.append($wrap, $loadingBay));

with

$(document.forms[0]).append($overlay, $box.append($wrap, $loadingBay));

This solves the problem as now you'll have the colorbox rendered div inside the form tag!!

于 2012-08-18T17:54:07.407 に答える