Contact
Send mail to the author(s) Email Me

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Sign In
Navigation

Tag Cloud
.NET Framework (27) AJAX (8) ASP.NET (14) C# (27) Cloud (1) Database (6) Dev Tools (2) Enterprise Library (1) Futures (1) General (5) Javascript (6) LINQ (2) Mobile (1) MSDTC (3) Quotes (3) SQL (3) Transactions (2) Visual Studio (3) WAS (2) WCF (13)

Archive
<July 2009>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Categories

Blogroll
Home Feed your aggregator (RSS 2.0)
# Saturday, February 10, 2007

I frequently place an UpdatePanel around a paged GridView with inline editing.   During OnRowUpdating, the object is saved.   If the save was not successful, I like to show an alert box with the error message.  

I recently migrated from the Atlas May CTP to ASP.NET 2.0 AJAX.   The following code worked with the May CTP, but, from my research, has not worked since July CTP:

Page.ClientScript.RegisterStartupScript(typeof(string), "alertScript", "alert('Error Message');", true);

However, our pals at Microsoft have given us something just as good.   I found it by mistake while trying to put in a hack involving checking the value of ScriptManager.GetCurrent(Page).IsInAsyncPostBack.  Here is the AJAX-friendly equivalent:

ScriptManager.RegisterStartupScript(this.updatePanel, typeof(string), "alertScript", "alert('Error Message');", true);

Hope this helps someone.  There are many blog posts, with many more comments, with people compaining about this.

Saturday, February 10, 2007 8:21:42 AM (Eastern Standard Time, UTC-05:00)  #    Comments [28]   AJAX | ASP.NET  | 
Saturday, April 21, 2007 12:09:00 PM (Eastern Standard Time, UTC-05:00)
Update:

I have altogether stopped using Page.ClientScript.RegisterStartupScript. For my AJAX apps, I now use my own ClientSide class to wrap ScriptManager.RegisterStartupScript. In the original post I showed using this.updatePanel as the first parameter for ScriptManager.RegisterStartupScript. In my ClientSide class I now have a property called page that gets System.Web.HttpContext.Current.Handler as System.Web.UI.Page to be used as the first parameter in ScriptManager.RegisterStartupScript. This way I always call ClientSide.RegisterScript or ClientSide.Alert from all of my pages, AJAX or not.
Scott
Wednesday, May 09, 2007 9:13:40 AM (Eastern Standard Time, UTC-05:00)
Thanks a lot.

I was looking for the same info :)
Monday, June 18, 2007 6:44:06 AM (Eastern Standard Time, UTC-05:00)
Thanks, I had the same problem and i've wasted a lot of time!
giorgia
Friday, June 29, 2007 9:50:11 AM (Eastern Standard Time, UTC-05:00)
I was looking for a solution for showing an alert box in my ajax app. in case of error. I found your article, but still cannot figure out how to do this. Could you please provide an example. Thank you
Diider
Thursday, July 19, 2007 8:22:12 AM (Eastern Standard Time, UTC-05:00)
Thanks

I was having the same problem :O)
Rodrigo Judice
Wednesday, August 01, 2007 8:12:54 AM (Eastern Standard Time, UTC-05:00)
Thanks Scott...I wish I would've looked here first!
Friday, August 10, 2007 4:31:06 AM (Eastern Standard Time, UTC-05:00)
You are the boss.!!!
Thanks Scott
Saturday, September 22, 2007 6:49:54 PM (Eastern Standard Time, UTC-05:00)
Nice. Big Thanks!
Friday, September 28, 2007 7:58:00 PM (Eastern Standard Time, UTC-05:00)
I cant tell you how much this has helped me.
Thank you so much ;)
Glynn Allen
Tuesday, October 09, 2007 11:42:34 AM (Eastern Standard Time, UTC-05:00)
Thanks a lot, It really helps me so much.
demo man
Thursday, October 25, 2007 5:26:05 PM (Eastern Standard Time, UTC-05:00)
My ASP.NET Ajax page has a LinkButton under the UpdatePanel. When clicking the link button, a new window page is opened up. Here is the event handler when clicking the link button:

protected void lbutton_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "open", "window.open('http://www.yahoo.com', 'newWindow', 'height=100, width=100, top=10, left=10, resizable=yes');", true);
}

A new window cannot be opened. If just using “window.open();”, it cannot be opened either. Both of them have this error: There is no source code available for the current location. Any comments about this error? Thanks.

Stock
Stock
Wednesday, November 14, 2007 3:54:35 AM (Eastern Standard Time, UTC-05:00)
Thank Scott!!
pakornss
Thursday, December 06, 2007 9:38:14 PM (Eastern Standard Time, UTC-05:00)
Thanks for posting this! I just added a couple UpdatePanels to a site and all of a sudden my popups stopped working (using ClientScript.REgister...). This got them going again.
Thursday, December 13, 2007 3:11:37 AM (Eastern Standard Time, UTC-05:00)
Thanks for posting this. I was looking forward for this.
Shabber Abbas
Tuesday, January 29, 2008 12:04:54 AM (Eastern Standard Time, UTC-05:00)
This was giving me headaches for ages, luckily I ran into your explanation here via Google. Mucho Gracias.

Regards
Stuart
Tuesday, February 05, 2008 7:29:26 AM (Eastern Standard Time, UTC-05:00)
Cool, the post.

Thanks for the information.
Monday, February 11, 2008 4:39:49 AM (Eastern Standard Time, UTC-05:00)
Many Thanks for this Scott. I wasted over a day trying to find a solution before stumbling upon your comments.
Simon Manning
Monday, February 18, 2008 1:24:09 AM (Eastern Standard Time, UTC-05:00)
Thank you very much! ^^
Lucky Man :)
Monday, February 18, 2008 4:52:23 AM (Eastern Standard Time, UTC-05:00)
Took me some time to figure out this was actualy the problem, i first tought it was the editindex of my gridview that didn't trigger the javascript expand function but it was the evil ajax :>

ty for mentioning this ;)
aalion
Wednesday, February 27, 2008 6:04:49 AM (Eastern Standard Time, UTC-05:00)
You are a legend!

I've been looking for this for ages. Thanks Scott, this helps me a lot!!!
Ian Sharpe
Sunday, March 23, 2008 2:18:25 AM (Eastern Standard Time, UTC-05:00)
Cool, the post.

Thanks for the information.
Wednesday, April 09, 2008 10:39:22 AM (Eastern Standard Time, UTC-05:00)
Yeah, I had been wracking my brains over this for a while now. Glad I stumbled across this. Thanks for the info!
Wednesday, May 14, 2008 8:55:31 PM (Eastern Standard Time, UTC-05:00)
Thanks!!! it helps me a lot
Friday, May 16, 2008 11:25:27 PM (Eastern Standard Time, UTC-05:00)
http://gooogle.com
ann
Saturday, May 24, 2008 4:25:30 AM (Eastern Standard Time, UTC-05:00)
Thanks , It is really helpfull ,
it helps me a lot

100/100
Walt
Monday, October 06, 2008 6:48:34 AM (Eastern Standard Time, UTC-05:00)
Thanks, I was searching for this. It solved my problem.
Jagjot
Wednesday, November 05, 2008 1:22:19 AM (Eastern Standard Time, UTC-05:00)
thanks man
Thursday, November 13, 2008 8:23:11 AM (Eastern Standard Time, UTC-05:00)
Merci beaucoup, c'est exactement ce que je cherchais.

Thanks a lot!
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2009 Scott Klueppel. All rights reserved.