2011-06-02 43 views
2

我有以下的javascript函数问题让我的jQuery的对话框打开并显示

<script type="text/javascript"> 
    function ShowAlert(id) { 
    // alert('I am here' + id); 
     $(id).dialog('open'); 

    } 

var dl; 
$(document).ready(function() { 
    //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" 
    }); 
      $("#<%=ButtonAdd.ClientID %>").click(function() { 
       var dl = $("#divDlg").dialog({ 
        //Setting up the dialog properties. 
        show: "blind", 
        hide: "fold", 
        resizable: false, 
        modal: true, 
        height: 400, 
        width: 700 
       }); 
       // dl.parent().appendTo(jQuery('form:first')); 
      }); 


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

}); 

在我的GridView的项目模板,我的编辑按钮,我有以下调用的函数。哪些工作来显示警报,但不能让它显示对话框?是否因为可能发生在网格上的回发导致它关闭?

<ItemTemplate> 
     <asp:Button ID="ButtonEdit" runat="server" CausesValidation="false" 
      CommandName="EditMember" OnClientClick='ShowAlert("#editPerson");' 
      Text="Edit" /> 
    </ItemTemplate> 

任何帮助将得到大大的appriated。

回答

0

我会在以客户端JavaScript代码中使用

$("#<%=ButtonAdd.ClientID %>").click(... 

非常谨慎。

更好的方法是使用jQuery的“attribute ends with”选择器。考虑到ASP.Net将您的ID从ASPX页面附加到其生成的HTML结尾(尝试在浏览器中加载页面后查看页面的源代码),这应该避开它 - 假设问题出在这里。