Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

Javascript Alert Popup on ItemUpdated

Need to have an alert fire after a formview updates.  Here is the code I have which is not working.
script language='javascript' type='text/javascript'> 
 
function confirmSelection() 
{ 
if (Page_IsValid) 
{ 
return confirm('Are you sure you want to delete this record?'); 
} 
else 
{ 
return false; 
} 
} 
 
</script> 
 
2. In your Page_Load event handler, add this line:
 
Me.fvLog.Attributes.Add("ItemUpdated", "return confirmSave()")

Open in new window

0
cadwal01
Asked:
cadwal01
  • 2
  • 2
1 Solution
 
cadwal01Author Commented:
Slight correction, I do have both the function names the same in my code.
0
 
guru_samiCommented:
So say you have a button Update in your FormView EditItemTemplate to update then try this:

<asp:Button ID="btnUpdate" CommandName="Update" runat="server" OnClientClick="return confirm('Are you certain you want to update?');" Text="Update" />
0
 
cadwal01Author Commented:
I want to give the user confirmation that the record has been saved/added.  They want a visual cue fro some reason.  So this would be after the ItemUpdated event.  Perhaps a hidden button with tthis code attached?
0
 
guru_samiCommented:
try something like this:
protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)
    {
        System.Text.StringBuilder script = new System.Text.StringBuilder();
        script.Append("<script language='javascript'>");
        script.Append("alert('Item Updated');");
        script.Append("</script>");
 
  Type t = this.GetType();
  if (!Page.ClientScript.IsStartupScriptRegistered(t, "AlertScript"))
  {
      Page.ClientScript.RegisterStartupScript(t, "AlertScript", script.ToString());
  }
}

For more info check this:
http://dotnetslackers.com/articles/aspnet/JavaScript_with_ASP_NET_2_0_Pages_Part1.aspx
http://archive.devnewz.com/devnewz-3-20061129JavaScriptAlertShowmessagefromASPNETCodebehind.html
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now