Solved

Javascript Alert Popup on ItemUpdated

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now