jquery - 从 Updatepanel 内的 Gridview rowcommand 调用 JQueryUI

标签 jquery asp.net gridview updatepanel jquery-ui-dialog

我已经被这个问题困扰了一段时间了。我一直在 stackoverflow 上寻找解决该问题的不同方法,但我仍然无法让它工作。它运行代码,但弹出窗口不会显示。当我将该方法放在更新面板外部的按钮上时,它会起作用。

我希望在单击 GridView 中的按钮字段时显示一个弹出窗口。

这是我的代码:

    <script type="text/javascript">
        function ShowPopup(message, title) {
            $(function () {
                $("#dialog").html(message);
                $("#dialog").dialog({
                    title: title,
                    buttons: {
                        Close: function () {
                            $(this).dialog('close');
                        }
                    },
                    modal: true
                });
            });
        };
</script>

<div id="dialog" style="display: none">

</div>

代码隐藏(我将解决问题的不同方法保留为评论):

protected void grdWallmessages_RowCommand(object sender, GridViewCommandEventArgs e)
{
    string message = "Meddelande borttaget från väggen!";
    string title = " Borttagning";
    ScriptManager.RegisterStartupScript(updwallmessages, updwallmessages.GetType(), Guid.NewGuid().ToString(), "ShowPopup('" + message + "','" + title + "');", true);

  //  ScriptManager.RegisterStartupScript(this, this.GetType(), "myalert", "alert('File already exists.');", true);
 //     Page.ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "','" + title + "');", true);
    try
    {
        DAL dal = new DAL();
        //Hämtar row index.
        int rowNum = int.Parse(e.CommandArgument.ToString());

        int id = Convert.ToInt32(grdWallmessages.Rows[rowNum].Cells[3].Text);
        dal.delete_wallmessages(id);


  //      ClientScript.RegisterStartupScript(this.GetType(), "Popup", "ShowPopup('" + message + "','" + title + "');", true);


        Response.Redirect("Profile.aspx");



    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }

}

GridView 和更新面板:

<asp:UpdatePanel ID="updwallmessages" runat="server">
    <ContentTemplate>
     <asp:GridView ID="grdWallmessages" runat="server" Height="159px" style="margin-top: 18px; margin-right: 0px;" Width="396px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowCommand="grdWallmessages_RowCommand" OnRowDataBound="grdWallmessages_RowDataBound">
         <Columns>
             <asp:ButtonField Text="Ta bort" />
         </Columns>
        </asp:GridView>
     </ContentTemplate>
</asp:UpdatePanel>

最佳答案

您无法在 ajax 上下文中创建 Response.Redirect("Profile.aspx");,当您将 GridView 代码保留在 UpdatePanel 中时会执行该上下文。

借助 Firebug 或 Chrome/Firefox 网络控制台检查服务器响应数据。

关于jquery - 从 Updatepanel 内的 Gridview rowcommand 调用 JQueryUI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21041412/

相关文章:

Android GridView 列拉伸(stretch)

asp.net - 将 gridview 与动态列绑定(bind)的简单方法是什么?

javascript - PNotify Confirm Module on Mobile with Modal 模式

jquery - 显示脚本无法使用一键操作(JQuery)

ASP.NET AJAX - 通过 JavaScript 检查异步回发

c# - MySqlProfileProvider 无法连接到我的数据库

javascript - jQuery UI 对话框在打开时不遵守位置选项

javascript - 优化 JQuery 中的每个循环

c# - 使双变量小于 1

asp.net - 如何构建像 DataBound Templated Custom ASP.NET Server Control 这样的 GridView