Reputation:
I've been stuck with this for some time now. I've been surfing stackoverflow for different approches to the problem but I still can't get it to work. It runs the code but the popup wont show. It works when I put the method on a button outside the updatepanel.
I want a popup to display when I click a buttonfield in the gridview.
Here is my code:
<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>
Codebehind(I kept my different approaches to my problem as comments):
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);
}
}
The gridview and updatepanel:
<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>
Upvotes: 2
Views: 1368
Reputation: 22619
You could not make Response.Redirect("Profile.aspx");
in a ajax context, which is executed when you keep your grid view code inside UpdatePanel.
Check the server response data, with the help of Firebug or Chrome/Firefox network console.
Upvotes: 1