0

みなさん、良い一日を、

以下は私のコードの一部です

開始コード
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script>loadAdditionalInfoDialog(info1)</script>",false);

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp2", "<script>loadAdditionalInfoDialog(info2)</script>",false);
}
コードの終わり

このloadAdditionalInfoDialog()関数は小さなウィンドウを表示し、ユーザーが情報を入力してから [OK] ボタンをクリックして次のステップに進みます。

しかし、Button1 をクリックすると、動作する 2 番目の のみが表示RegisterStartupScriptloadAdditionalInfoDialog(info2)れ、小さなウィンドウが表示され、情報を入力して [OK] ボタンをクリックして次のステップに進むことができます。

RegisterStartupScriptこのため、最初の、つまりの情報を入力できませんloadAdditionalInfoDialog(info1)

Button1 をクリックすると、最初に の情報を入力しloadAdditionalInfoDialog(info1)てから [OK] ボタンをクリックしてから、 の情報を入力し続けることができるという解決策をお願いしたいと思いますloadAdditionalInfoDialog(info2)

千の感謝。

実際、Button1_Click は、テストを行うために作成した単なるボタンです。実際、 Repeater でデータを取得する場合にのみ、 loadAdditionalInfoDialog() を呼び出します。

protected void btnRedeemAll_Click(object sender, EventArgs e)
    {
        foreach( RepeaterItem itm in repGiftResults.Items )
        {
            /*
            code to get all those parameter
            */
            if (pr.AdditionalFieldsEnabled == true)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "<script>loadAdditionalInfoDialog(1," + pr.ID + "," + giftId + ",'" + txtQty.ClientID + "'," + tokenId + ")</script>", false);
                        
                    }
        }
    }

したがって、リピーターで多くのパラメーターを取得する必要があるため、「OK」ボタンをクリックしたときに2回目の loadAdditonalInfoDialog() を呼び出すのは難しいと思います。

4

2 に答える 2

1

さて、コードは正常に動作するはずです。info1 と info2 が定義されていることを確認し、loadAdditionalInfoDialog のロジックを修正してください。テストのためだけにアラートを入れます。また、1 つのブロックで両方の呼び出しを行うこともできます。

更新:コメントからあなたがやりたいことは次のとおりです。

リピーターテンプレートに非表示フィールドを追加します

 <asp:HiddenField ID="hdf" runat="server" />

あなたのコードビハインドでは、このようなことを試すことができます

        foreach (RepeaterItem item in cdcatalog.Items)
        {
            // Put your condition here like  if (pr.AdditionalFieldsEnabled == true) in my case to make it simple I'm just using the index
            if (item.ItemIndex == 1)
            {
                //Get the hidden fiels to save your parameters for the next call you can add multiple parameters 1;2;3;4 and read it using js
                HiddenField hdf = item.FindControl("hdf") as HiddenField;
                hdf.Value = "info2";
                // Pass the client ID for the hidden field so you can access it in loadAdditionalInfoDialog to retrieve parameter
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), String.Format("temp_{0}",item.ItemIndex),
                                                   String.Format("<script>loadAdditionalInfoDialog('info1',{0});</script>",hdf.ClientID),
                                                    false);
            }
        }

スクリプトでは、次のようなことができます。

 <script type="text/javascript">
        function loadAdditionalInfoDialog(param, hdfId) {
            // Do whatever yout want here
            var info = prompt("Please enter ", param);

            if (info != null) {
                // Do whatever you want with the info you collected 

                // This code should be in your ok click button to check whether you should call the second window.
                if (info !== undefined) {
                    loadAdditionalInfoDialog(hdfId.value);
                }
            }


        }

    </script>

これが役立つことを願っています。

于 2013-06-10T08:31:19.970 に答える
1

あなたがまだこれを行う方法を探しているなら。これは私にとってうまくいったもので、あなたの例に実装されています:

protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "temp", "    <script>loadAdditionalInfoDialog(info1); loadAdditionalInfoDialog(info2); </script>",false);

}

2 つのプロセスを 1 つにまとめました。最初に 1 つを実行し、次に 2 つ目を実行する必要がある場合は、役立つかもしれません

于 2013-10-09T20:52:35.987 に答える