2013-12-09 48 views
0

我有这个我正在处理的asp页面,它有一个gridview控件,它有编辑按钮。我可以通过编辑按钮来显示JQuery UI对话框。问题是,当我点击按钮时,对话框打开,然后很快关闭。这里是为GridView的标记:当我点击GridView中的编辑按钮时,JQuery UI对话框消失

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     BackColor="White" BorderColor="#CCCCCC" 
     BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" 
     OnRowDataBound="GridView1_RowDataBound" 
     style="margin-bottom: 0px" > 
     <Columns> 
       <asp:TemplateField HeaderText="Edit"> 
        <ItemTemplate> 
          <asp:LinkButton Id="btnEditRow" Text="Edit" OnClientClick="EditRecordOpen('editForm');" OnClick="btnEditRow_Click" runat="server" /> 
         </ItemTemplate> 
       </asp:TemplateField> 
       <asp:BoundField DataField="StartTime" HeaderText="Start Time" 
         SortExpression="StartTime" > 
         <ItemStyle Width="180px" /> 
       </asp:BoundField> 
     </Columns> 
</asp:GridView> 

这是我的JavaScript是什么样子:

<script type="text/javascript"> 
     $(document).ready(function() { 
      $("#editForm").dialog({ 
       autoOpen: false, 
       draggable: true, 
       title: "Edit Record", 
       open: function (type, data) { 
        $(this).parent().appendTo("form"); 
       } 
      }); 
     }); 

     function EditRecordOpen(id) { 
      $("#" + id).dialog("open"); 
      return false; 
     } 

     function EditRecordClose(id) { 
      $("#" + id).dialog("close"); 
      return false; 
     } 
</script> 

我在另一StackOverflow的问题读取放置

return false; 

将停止行为但它仍然消失。

有3个功能控制与对话,以及相关的按钮点击:

private void CloseDialog(string dialogId) 
{ 
     string script = string.Format(@"closeDialog('{0}')", dialogId); 
     ScriptManager.RegisterClientScriptBlock(this, typeof(Page), UniqueID, script, true); 
} 

protected void btnSaveRecord_Click(object sender, EventArgs e) 
{ 
     CloseDialog("editForm"); 
} 

protected void btnEditRow_Click(object sender, EventArgs e) 
{ 
     var editLink = ((LinkButton)sender); 
     editRecordPanel.Update(); 
} 

我使用Chrome开发者工具,以及看到点击期间发生了什么尝试过,但我没有看到与对话有关的任何错误。

另外,我用的样品从http://blog.roonga.com.au/2009/07/using-jquery-ui-dialog-with-aspnet-and.html页面设置对话框

而且,我的弹出窗口定义如下:

<div id="editForm"> 
    <asp:UpdatePanel ID="editRecordPanel" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server"> 
      <ContentTemplate> 
       <asp:Label ID="popupTest" runat="server" Text="Test"></asp:Label> 
       <asp:Button ID="btnSaveRecord" runat="server" Text="Save" OnClick="btnSaveRecord_Click" /> 
      </ContentTemplate> 
     </asp:UpdatePanel> 
</div> 
+2

UpdatePanel里面是所有的东西吗? - 从第二眼看到的内容出现后,通过调用后面的代码进行回发。该对话框无法阻止/停止发布回复,就像提出问题的唯一浏览器对话框一样。所以是正常的,你打开对话框,然后关闭,因为回发和页面重新加载。 – Aristos

+0

所以这就是为什么对话只显示一秒钟?我怎么能阻止呢?另外,我把所有的标记放在问题的弹出窗口中。我最初忘了补充一点。 – user

+1

放置OnClientClick =“EditRecordOpen('editForm');返回false;”'然后你打开对话框,但我不知道你想要做什么 – Aristos

回答

0

得到它的工作,@Aristos帮我找出我放置

return false; 

OnClientClick="EditRecordOpen('editForm'); return false;" 
需要