Solved

Javascript Alert Popup on ItemUpdated

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

756 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