Solved

Javascript Alert Popup on ItemUpdated

Posted on 2009-07-02
4
409 Views
Last Modified: 2012-05-07
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
Comment
Question by:cadwal01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 

Author Comment

by:cadwal01
ID: 24766206
Slight correction, I do have both the function names the same in my code.
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 24766563
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
 

Author Comment

by:cadwal01
ID: 24767017
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
 
LVL 41

Accepted Solution

by:
guru_sami earned 500 total points
ID: 24768004
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question