Solved

Javascript Alert Popup on ItemUpdated

Posted on 2009-07-02
4
395 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How come this regular expression allows "e"? 14 38
C# LINQ ForEach() question 6 28
Index on a Table 6 14
How to reload page and grab querystring 2 10
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

773 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