Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Wednesday, April 04, 2007

Say you have a master page and content page scenario, and from the content page you want to interact with DOM elements described from the master page (for example, the main body element). This is how I do it:

First, add the following attributes to your body element so that it is included in the server-side runtime and can be interacted with from there:

<body id="mainbody" runat="Server">

...notice how the body element now has an id and has the runat="server" attribute set.

Second, from code within the content page (I'm doing it in Page_Load) add code like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        HtmlGenericControl ctrl = (HtmlGenericControl)this.Master.FindControl("mainbody");
        ctrl.Attributes.Add("onload", "alert('hello');");
        return;
    }

The key here is to now grab the body element, add some script to it, and then let it all run as normal. When I run the solution, the content page is loaded, its Page_Load called, the script injected into the body element (of the master page) and I see "hello".

Recommended reading:

kick it on DotNetKicks.com
Tuesday, April 03, 2007 11:47:56 PM (Central Standard Time, UTC-06:00)  #    Comments [2] - Trackback
AJAX | ASP.Net | Computing
Tracked by:
http://freewebs.com/aspxfaq/05/sitemap12.html [Pingback]
http://freewebs.com/toltom/06/sitemap10.html [Pingback]
http://freewebs.com/toltom/09/luggage.html [Pingback]
http://freewebs.com/toltom/14/sitemap15.html [Pingback]
http://freewebs.com/toltom/00/index.html [Pingback]
"http://fartooblog.tripod.com/172.html" (http://fartooblog.tripod.com/172.html) [Pingback]
"http://fartooblog.tripod.com/54.html" (http://fartooblog.tripod.com/54.html) [Pingback]
"http://awlelm.org/sitemap46.html" (http://awlelm.org/sitemap46.html) [Pingback]
"http://guzahm.org/cricket-cell-phones.html" (http://guzahm.org/cricket-cell-pho... [Pingback]
"http://topslots.nl.eu.org/15/sitemap6.html" (http://topslots.nl.eu.org/15/sitem... [Pingback]
"http://freewebs.com/amexa/02/wells-fargo-home-mortgage.html" (http://freewebs.c... [Pingback]
"http://freewebs.com/amexa/18/bad-credit-refinance.html" (http://freewebs.com/am... [Pingback]
"http://freewebs.com/amexa/30/best-weight-loss-pills.html" (http://freewebs.com/... [Pingback]
"http://pinofranc.homestead.com/04/sperm-shack.html" (http://pinofranc.homestead... [Pingback]
"http://pinofranc.homestead.com/01/bristol-herald-courier.html" (http://pinofran... [Pingback]
"http://pinofranc.homestead.com/03/american-eagle-wheels.html" (http://pinofranc... [Pingback]
"http://kfpye-xxx.com/clean-penis.html" (http://kfpye-xxx.com/clean-penis.html) [Pingback]
"http://aixpj-www.com/free-mature-mpegs.html" (http://aixpj-www.com/free-mature-... [Pingback]
"http://pohteenews.tripod.com/0.html" (http://pohteenews.tripod.com/0.html) [Pingback]
"http://caploonews.tripod.com/43.html" (http://caploonews.tripod.com/43.html) [Pingback]
"http://gacmuunews.angelfire.com/163.html" (http://gacmuunews.angelfire.com/163.... [Pingback]
"http://ywwhr-ooo.com/big-breasts-big-jugs.html" (http://ywwhr-ooo.com/big-breas... [Pingback]
"http://lasduunews.angelfire.com/142.html" (http://lasduunews.angelfire.com/142.... [Pingback]
"http://cnk6d-hhh.com/janet-jackson-topless.html" (http://cnk6d-hhh.com/janet-ja... [Pingback]
"http://y2zyu-xxx.biz/nude-olympic-female-athlete.html" (http://y2zyu-xxx.biz/nu... [Pingback]
"http://naidu-www.biz/girls-porn.html" (http://naidu-www.biz/girls-porn.html) [Pingback]
"http://omu8u-eee.com/naked-female-ass.html" (http://omu8u-eee.com/naked-female-... [Pingback]
"http://freewebs.com/amexa/00/homeowners-insurance.html" (http://freewebs.com/am... [Pingback]
"http://freewebs.com/niret/06/www-dallascowboys-com.html" (http://freewebs.com/n... [Pingback]
"http://freewebs.com/gremi/10/outro-learning-399616.html" (http://freewebs.com/g... [Pingback]
"http://freewebs.com/bermut/13/round-steak-recipes.html" (http://freewebs.com/be... [Pingback]
"http://freewebs.com/amexa/22/winston-patio-furniture.html" (http://freewebs.com... [Pingback]
"http://mwjec-rrr.com/pussy-wired.html" (http://mwjec-rrr.com/pussy-wired.html) [Pingback]
"http://www.freewebtown.com/unibetkom/0019-blog.html" (http://www.freewebtown.co... [Pingback]
"http://ramambo.nl.eu.org/07/hsbccreditcard.html" (http://ramambo.nl.eu.org/07/h... [Pingback]
"http://harum.nl.eu.org/sportsillistrated-com.html" (http://harum.nl.eu.org/spor... [Pingback]
"http://ramambo.nl.eu.org/fernandina-beach.html" (http://ramambo.nl.eu.org/ferna... [Pingback]
"http://grgh1aa.biz/sitemap32.html" (http://grgh1aa.biz/sitemap32.html) [Pingback]
"http://mordor.nl.eu.org/naked-latin-girls.html" (http://mordor.nl.eu.org/naked-... [Pingback]
"http://asfenato.nl.eu.org/pergo-laminate-flooring.html" (http://asfenato.nl.eu.... [Pingback]
"http://sevorokom.nl.eu.org/hot-black-pussy.html" (http://sevorokom.nl.eu.org/ho... [Pingback]
"http://mv8oyh3.biz/sexy-booty.html" (http://mv8oyh3.biz/sexy-booty.html) [Pingback]
"http://nasferablog.netfirms.com/113.html" (http://nasferablog.netfirms.com/113.... [Pingback]
"http://farotblog.nl.eu.org/heraldandnews-com.html" (http://farotblog.nl.eu.org/... [Pingback]
"http://farotblog.nl.eu.org/rancho-animal-shelter.html" (http://farotblog.nl.eu.... [Pingback]
"http://uykrmbb.biz/underage-little-girls.html" (http://uykrmbb.biz/underage-lit... [Pingback]
"http://abo--blog.nl.eu.org/sears-store.html" (http://abo--blog.nl.eu.org/sears-... [Pingback]
"http://nasferablog.netfirms.com/209.html" (http://nasferablog.netfirms.com/209.... [Pingback]
"http://lk2iuen.biz/breast-stimulation.html" (http://lk2iuen.biz/breast-stimulat... [Pingback]
"http://nasferablog.netfirms.com/339.html" (http://nasferablog.netfirms.com/339.... [Pingback]
"http://qcdals1.biz/maple-story-cheats.html" (http://qcdals1.biz/maple-story-che... [Pingback]
"http://valwgki.biz/miami-dade-schools.html" (http://valwgki.biz/miami-dade-scho... [Pingback]
"http://newa--lono.nl.eu.org/the-indianapolis-star.html" (http://newa--lono.nl.e... [Pingback]
"http://radafe--loto.nl.eu.org/ps3-com.html" (http://radafe--loto.nl.eu.org/ps3-... [Pingback]
"http://nasferablog.netfirms.com/110.html" (http://nasferablog.netfirms.com/110.... [Pingback]
"http://jmqp7tr.biz/www.tracphone.com.html" (http://jmqp7tr.biz/www.tracphone.co... [Pingback]
"http://wwad6lf.biz/www.bankofameric.html" (http://wwad6lf.biz/www.bankofameric.... [Pingback]
"http://freewebs.com/fremapblog/sitemap2.html" (http://freewebs.com/fremapblog/s... [Pingback]
"http://freewebs.com/sruone/www-kohler-com.html" (http://freewebs.com/sruone/www... [Pingback]
"http://freewebs.com/sruone/sitemap351.html" (http://freewebs.com/sruone/sitemap... [Pingback]
"http://galetgah.homestead.com/12.html" (http://galetgah.homestead.com/12.html) [Pingback]
"http://pk3p6fu.info/christina-aguilera-nude.html" (http://pk3p6fu.info/christin... [Pingback]
"http://freewebs.com/vuter/07/kentucky-state-police.html" (http://freewebs.com/v... [Pingback]
"http://buter.homestead.com/01/bay-area-real-estate-information.html" (http://bu... [Pingback]
"http://freewebs.com/vuter/00/sitemap4.html" (http://freewebs.com/vuter/00/sitem... [Pingback]
"Software Development Guide" (Software Development Guide) [Trackback]
"http://euter.homestead.com/00/save-the-last-dance-soundtrack.html" (http://eute... [Pingback]
"http://freewebs.com/datingblogger/739.html" (http://freewebs.com/datingblogger/... [Pingback]
"http://freewebs.com/datingblogger/1247.html" (http://freewebs.com/datingblogger... [Pingback]
"Programming Tutorials" (Programming Tutorials) [Trackback]
"http://fasxen.netfirms.com/11.html" (http://fasxen.netfirms.com/11.html) [Pingback]

Computers Blogs - Blog Top Sites

Archive
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
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 2008
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 127
Themes
Pick a theme:
All Content © 2008, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)