如何从asp.net按钮单击事件调用javascript函数

前端之家收集整理的这篇文章主要介绍了如何从asp.net按钮单击事件调用javascript函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何从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",title: "Modify Member",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>

试图从gridview编辑按钮调用jquery对话框并获得相同的错误对象不支持属性方法

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

解决方法

如果按下此按钮时不需要发回帖子,则无需进行服务器控件的开销.
<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>
原文链接:https://www.f2er.com/aspnet/251073.html

猜你在找的asp.Net相关文章