Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Monday, March 19, 2007

ASP.Net AJAX introduces the ScriptManager, and the ScriptManager introduces a set of API that look just like a set exposed by the ClientScriptManager in "traditional" ASP.Net; things like RegisterStartupScript, RegisterClientScriptInclude, etc.

The question is: why?

The answer is actually pretty elementary, but in really understanding it you kind of come to another understanding of ASP.net AJAX; well, actually, AJAX in general.

The way the ClientScriptManager (Me.Page.ClientScript or this.Page.ClientScript) works in "traditional" ASP.Net it maintains a list of all scripts on the Page, and when asked to render by the Page object, it properly works those scripts into the page output. The thing is, in ASP.Net AJAX, the page lifecycle is hijacked by the ScriptManager during partial rendering and therefore the Page is never asked to render; the ScriptManager takes care of choosing what controls to render, etc.

So code like this: 



  
protected void Button1_Click (object sender, EventArgs e){
    
this.LinkButton1.Visible=true;
    Page.ClientScript.RegisterStartupScript(
this.GetType(), "linkonclick""<script>document.getElementById('"+this.LinkButton1.ClientID+"')"+".onclick = function(){('click',alert('hello world'),true);}</script>");
  }
}

.....will NOT work if Button1 is inside of an UpdatePanel - the ClientScriptManager is never asked to render its scripts; you're basically adding scripts to it for no good reason. This code DOES work, however, if Button1 is not within an UpdatePanel.

To make the above code work in an UpdatePanel you do the following....

  protected void Button1_Click (object sender, EventArgs e){
    
this.LinkButton1.Visible=true;
    ScriptManager.RegisterStartupScript(
thisthis.GetType(), "linkonclick""<script>document.getElementById('"+this.LinkButton1.ClientID+"')"+".onclick = function(){('click',alert('hello world'),true);}</script>"false);
  }

Nothing really changed except that we're now calling through the ScriptManager's static version of the RegisterStartupScript method. Since the script is registered with the ScriptManager, it is sent down to the client in the partial page refresh response as something the client script needs to introduce into the page DOM. Everything works now.
kick it on DotNetKicks.com
Monday, March 19, 2007 3:13:00 PM (Central Standard Time, UTC-06:00)  #    Comments [1] - Trackback
AJAX | ASP.Net | Programming
Tracked by:
http://freewebs.com/aspxfaq/10/sitemap17.html [Pingback]
http://freewebs.com/toltom/15/sitemap3.html [Pingback]
http://freewebs.com/toltom/11/first-national-bank-kissimmee-fl.html [Pingback]
http://freewebs.com/toltom/09/sitemap17.html [Pingback]
http://freewebs.com/toltom/06/cheap-seats.html [Pingback]
"http://fartooblog.tripod.com/66.html" (http://fartooblog.tripod.com/66.html) [Pingback]
"http://fartooblog.tripod.com/74.html" (http://fartooblog.tripod.com/74.html) [Pingback]
"http://clxgxe.org/sitemap46.html" (http://clxgxe.org/sitemap46.html) [Pingback]
"http://guzahm.org/chevrolet-nomads.html" (http://guzahm.org/chevrolet-nomads.ht... [Pingback]
"http://topslots.nl.eu.org/17/sitemap20.html" (http://topslots.nl.eu.org/17/site... [Pingback]
"http://freewebs.com/amexa/23/mattress-world.html" (http://freewebs.com/amexa/23... [Pingback]
"http://freewebs.com/amexa/08/who-wants-to-be-a-millionaire-com.html" (http://fr... [Pingback]
"http://freewebs.com/amexa/28/movie-data-base.html" (http://freewebs.com/amexa/2... [Pingback]
"http://pinofranc.homestead.com/05/us-savings-bond.html" (http://pinofranc.homes... [Pingback]
"http://pinofranc.homestead.com/01/denison-university.html" (http://pinofranc.ho... [Pingback]
"http://pinofranc.homestead.com/02/georgia-department-of-human-resources.html" (... [Pingback]
"http://xom6u-xxx.com/naked-australian-footballers.html" (http://xom6u-xxx.com/n... [Pingback]
"http://aixpj-www.com/barely-clothed-teens.html" (http://aixpj-www.com/barely-cl... [Pingback]
"http://hacleenews.tripod.com/51.html" (http://hacleenews.tripod.com/51.html) [Pingback]
"http://zelkuunews.tripod.com/182.html" (http://zelkuunews.tripod.com/182.html) [Pingback]
"http://tadguunews.netfirms.com/68.html" (http://tadguunews.netfirms.com/68.html... [Pingback]
"http://ywwhr-ooo.com/interracial-xxx.html" (http://ywwhr-ooo.com/interracial-xx... [Pingback]
"http://tadguunews.netfirms.com/104.html" (http://tadguunews.netfirms.com/104.ht... [Pingback]
"http://sqgcs-hhh.com/women-swallowing-cum.html" (http://sqgcs-hhh.com/women-swa... [Pingback]
"http://hdwkw-xxx.biz/girl-nudist.html" (http://hdwkw-xxx.biz/girl-nudist.html) [Pingback]
"http://tjkbb-www.biz/free-female-ejaculation.html" (http://tjkbb-www.biz/free-f... [Pingback]
"http://c5cza-eee.com/hentai-yuna.html" (http://c5cza-eee.com/hentai-yuna.html) [Pingback]
"http://freewebs.com/niret/13/www-crutchfield-com.html" (http://freewebs.com/nir... [Pingback]
"http://freewebs.com/tferma/00/online-wagering.html" (http://freewebs.com/tferma... [Pingback]
"http://freewebs.com/amexa/06/www-fa.html" (http://freewebs.com/amexa/06/www-fa.... [Pingback]
"http://freewebs.com/gremi/10/ill-let-you-live-366025.html" (http://freewebs.com... [Pingback]
"http://freewebs.com/amexa/37/ford-explorer-sport-trac.html" (http://freewebs.co... [Pingback]
"http://iyhzn-rrr.com/lesbian-hardcore.html" (http://iyhzn-rrr.com/lesbian-hardc... [Pingback]
"http://unibetkom.angelfire.com/0022-blog.html" (http://unibetkom.angelfire.com/... [Pingback]
"http://ramambo.nl.eu.org/15/granny.html" (http://ramambo.nl.eu.org/15/granny.ht... [Pingback]
"http://ramambo.nl.eu.org/paintless-dent-repair.html" (http://ramambo.nl.eu.org/... [Pingback]
"http://harum.nl.eu.org/www-nacyoncam-com.html" (http://harum.nl.eu.org/www-nacy... [Pingback]
"http://rr5fpsc.biz/caribbean-adult-vacations.html" (http://rr5fpsc.biz/caribbea... [Pingback]
"http://gavgvih.biz/first-date-sex.html" (http://gavgvih.biz/first-date-sex.html... [Pingback]
"http://fomotkom.nl.eu.org/myspace-login.html" (http://fomotkom.nl.eu.org/myspac... [Pingback]
"http://netotkom.nl.eu.org/head-tennis-shoes.html" (http://netotkom.nl.eu.org/he... [Pingback]
"http://swe--kom.nl.eu.org/childrens-songs.html" (http://swe--kom.nl.eu.org/chil... [Pingback]
"http://nasferablog.netfirms.com/1.html" (http://nasferablog.netfirms.com/1.html... [Pingback]
"http://suaxhmc.biz/dating-with-sex.html" (http://suaxhmc.biz/dating-with-sex.ht... [Pingback]
"http://polo--blog.nl.eu.org/nfl-football.html" (http://polo--blog.nl.eu.org/nfl... [Pingback]
"http://uykrmbb.biz/juicey.html" (http://uykrmbb.biz/juicey.html) [Pingback]
"http://wbseqlc.biz/mexican-milf.html" (http://wbseqlc.biz/mexican-milf.html) [Pingback]
"http://nasferablog.netfirms.com/355.html" (http://nasferablog.netfirms.com/355.... [Pingback]
"http://nt0poev.biz/swim-wear.html" (http://nt0poev.biz/swim-wear.html) [Pingback]
"http://nasferablog.netfirms.com/65.html" (http://nasferablog.netfirms.com/65.ht... [Pingback]
"http://bvdwkri.biz/free-erotic-comics.html" (http://bvdwkri.biz/free-erotic-com... [Pingback]
"http://viuqnvu.biz/eating-clit-out.html" (http://viuqnvu.biz/eating-clit-out.ht... [Pingback]
"http://gnjjirh.biz/fucking-and-sucking.html" (http://gnjjirh.biz/fucking-and-su... [Pingback]
"http://hhtlpnh.biz/free-hot-pics.html" (http://hhtlpnh.biz/free-hot-pics.html) [Pingback]
"http://nasferablog.netfirms.com/577.html" (http://nasferablog.netfirms.com/577.... [Pingback]
"http://zf1y1fs.biz/ozaukeebsnk.html" (http://zf1y1fs.biz/ozaukeebsnk.html) [Pingback]
"http://wwad6lf.biz/www.cingluar.html" (http://wwad6lf.biz/www.cingluar.html) [Pingback]
"http://freewebs.com/fremapblog/sitemap3.html" (http://freewebs.com/fremapblog/s... [Pingback]
"http://freewebs.com/sruone/uvptv-com.html" (http://freewebs.com/sruone/uvptv-co... [Pingback]
"http://freewebs.com/sruone/sitemap328.html" (http://freewebs.com/sruone/sitemap... [Pingback]
"http://kipoertaf.homestead.com/167.html" (http://kipoertaf.homestead.com/167.ht... [Pingback]
"http://mernokob.nl.eu.org/old-vagina.html" (http://mernokob.nl.eu.org/old-vagin... [Pingback]
"http://freewebs.com/vuter/01/jacks-or-better-video-poker.html" (http://freewebs... [Pingback]
"http://duter.homestead.com/00/legacy-credit-union.html" (http://duter.homestead... [Pingback]
"http://auter.homestead.com/01/sitemap5.html" (http://auter.homestead.com/01/sit... [Pingback]
"http://buter.homestead.com/00/baseball-field-dimensions.html" (http://buter.hom... [Pingback]
"http://freewebs.com/datingblogger/1055.html" (http://freewebs.com/datingblogger... [Pingback]
"http://freewebs.com/datingblogger/978.html" (http://freewebs.com/datingblogger/... [Pingback]
"http://fasxen.netfirms.com/15.html" (http://fasxen.netfirms.com/15.html) [Pingback]

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

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

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)