4

asp.net ボタン クリック イベントから showDialog を呼び出すにはどうすればよいですか。マイページは、マスターページが関連付けられたコンテンツページです。

私は次のことを試しました

<asp:Button ID="ButtonAdd" runat="server" Text="Add" 
                            OnClientClick="showDialog('#addPerson');" />
  <asp:Button ID="ButtonAdd" runat="server" Text="Add" 
                            OnClientClick="showDialog(#<%=addPerson.ClientID %>);" />

ダイアログのレコードを変更するには、gridview テンプレート ボタンから同じ関数を呼び出す必要もあります。

<script type="text/javascript">


    // Used the following example to open the dialog withJquery 
        var dl;
        $(document).ready(function () {

            //Adding the event of opening the dialog from the asp.net add button.
            //setup edit person dialog             
            $('#addPerson').dialog({
                //Setting up the dialog properties.
                show: "blind",
                hide: "fold",
                resizable: false,
                modal: true,
                height: 400,
                width: 700,
                title: "Add New Member",
                open: function (type, data) {
                    $(this).parent().appendTo("form:first");
                }
            });

            //setup edit person dialog             
            $('#editPerson').dialog({
                //Setting up the dialog properties.
                show: "blind",
                hide: "fold",
                resizable: false,
                modal: true,
                height: 400,
                width: 700,
                title: "Modify Member",
                open: function (type, data) {
                    $(this).parent().appendTo("form");
                }             
            });



            function showDialog(id) {
                $('#' + id).dialog("open"); 
            } 



    //        function closeDialog(id) {
    //            $('#' + id).dialog("close"); 
    //        } 

            //Adding a event handler for the close button that will close the dialog 
            $("a[id*=ButtonCloseDlg]").click(function (e) {
                $("#divDlg").dialog("close");
                return false;
            });
        });

       </script>

グリッドビューの編集ボタンから jquery ダイアログを呼び出そうとしましたが、同じエラー オブジェクトはこのプロパティまたはメソッドをサポートしていませんか?

<input type="submit" name="ctl00$ContentPlaceHolder1$GridViewMembers$ctl02$Button1" value="Edit" onclick="showDialog(&#39;addPerson&#39;);" id="ContentPlaceHolder1_GridViewMembers_Button1_0" />
4

2 に答える 2

8

このボタンを押したときにポスト バックを開始する必要がない場合は、サーバー コントロールのオーバーヘッドを作成する必要はありません。

<input id="addButton" type="button" value="Add" />

<script type="text/javascript" language="javascript">
     $(document).ready(function()
     {
         $('#addButton').click(function() 
         { 
             showDialog('#addPerson'); 
         });
     });
</script>

それでもポストバックを実行できるようにする必要がある場合は、少し異なるコードを使用して、残りのボタン アクションを条件付きで停止できます。

<asp:Button ID="buttonAdd" runat="server" Text="Add" />

<script type="text/javascript" language="javascript">
     $(document).ready(function()
     {
         $('#<%= buttonAdd.ClientID %>').click(function(e) 
         { 
             showDialog('#addPerson');

             if(/*Some Condition Is Not Met*/) 
                return false;
         });
     });
</script>
于 2011-06-01T14:59:51.160 に答える
3

関数の先頭に既にハッシュ記号が追加されてshowDialog()おり、2 番目のコード スニペットに一重引用符がありません。falseまた、ポストバックが発生しないように、ハンドラーから戻る必要があります。試す:

<asp:Button ID="ButtonAdd" runat="server" Text="Add"
    OnClientClick="showDialog('<%=addPerson.ClientID %>'); return false;" />
于 2011-06-01T14:59:32.033 に答える