0

コードビハインドでいくつかのボタンクリックでモデルポップアップを開きたいのですが、if else条件がいくつかあります。まず第一に、最善のアプローチを修正することができません。私が考えるオプションは次のとおりです。1) jquery モデル ポップアップの呼び出し 2) ajax モデル ポップアップ

これは、モデル ポップアップを開くボタン クリック条件を修正するボタンです。モデル ポップが「はい」と答えた場合、クライアントにアイテムを購入するために支払う支払いページにリダイレクトしてもらいます。

現在、私はこのように呼び出しているJqueryモデルのポップアップを使用しています

 protected void imgClientFreeEval_Click(object sender, System.Web.UI.ImageClickEventArgs e)
    {
-----
---some code not typed
 if (SurveyCount > 1)
            {
                Session["YourAssessment"] = true;
                Session["MyAssessment"] = false;
                ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", "<script>xyz()</script>", true);
                //Response.Redirect("~/yourAssessment.aspx");

            }
}

そして、私はこのようなモデルポップアップを持っています

 function xyz() {
            //  alert('hi tpo all');
            // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
            //            $("#dialog:ui-dialog").dialog("destroy");
            $(document).ready(function () {
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 140,
                    modal: true,
                    autoOpen: false,
                    buttons: {
                        "OK": function () {
                            $(this).dialog("close");
                            window.location.replace("http://stackoverflow.com");

                        },
                        Cancel: function () {
                        window.location.replace("http://stackoverflow.com");
                            $(this).dialog("close");
                        }
                    }
                });
            });
        }

問題は、この関数がまったく呼び出されないことです。これの何が問題なのか、私は長い間苦労しています。可能であれば、どのように実行するのが最善のアプローチかを提案してください。ボタンクリックの背後にあるコードからこの javasccipt 関数を呼び出すことができません。

4

4 に答える 4

1

コードビハインドから JavaScript アラートを取得するために使用する方法は次のとおりです。

public void AMessage(string message)
{
    ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "info only", "alert('" + message + "');", true);
}

ボタンで OnClientClick イベントを使用していない場合は、同様のハンドラーを介してメッセージを送信します。あなたの場合、呼び出す代わりに、"alert('" + message + "');"作成した関数を呼び出します。

于 2012-05-21T12:14:43.817 に答える
0

あなたのコードで指摘した問題の 1 つは、次の行にあります。

ScriptManager.RegisterStartupScript(this, this.GetType(), "tmp", "<script>xyz()</script>", true);

最後のパラメーターである addScriptTags を true として渡していますが、既にスクリプト タグを呼び出しに追加しているため、そこで問題が発生している可能性があります。

乾杯

于 2012-05-21T13:33:02.243 に答える
0

これを使ってみてください:

function xyz() {
            //  alert('hi tpo all');
            // a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
            //            $("#dialog:ui-dialog").dialog("destroy");
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 140,
                    modal: true,
                    autoOpen: false,
                    buttons: {
                        "OK": function () {
                            $(this).dialog("close");
                            window.location.replace("http://stackoverflow.com");

                        },
                        Cancel: function () {
                        window.location.replace("http://stackoverflow.com");
                            $(this).dialog("close");
                        }
                    }
                });
            });
        }
于 2012-05-21T12:15:01.347 に答える
0

アラートを受け取り、[OK] をクリックしたときにページをリダイレクトする場合。次のように試すことができます:

ClientScript.RegisterStartupScript(this.GetType(), "My alert", "alert('" Your time has been finished "');", true);
    System.Text.StringBuilder sbs = new System.Text.StringBuilder();
    sbs.Append("<script language='javascript'>");
    sbs.Append("window.location = 'http://www.google.com/'");//or whatever you want:-
    sbs.Append("</script>");
    Type tr = this.GetType();
    ClientScript.RegisterClientScriptBlock(tr, "PopupScript2", sbs.ToString());
于 2012-05-21T12:25:41.750 に答える