Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Body.Attributes.Add

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mazdotnet - 24 Aug 2007 19:43 GMT
Hi,

I have a master file with the following setting
<body runat="server" id="Body">
and in the .cs I have
Body.Attributes.Add("onload",
"menuCurrentPage('current','navlist');");

Now in one of my content files I want to add an additional parameter
to the onload
HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes.Add("onload", "alert('hello world');");

However, this overwrites the value in my onload attribute on the
master page and so I lose 'menuCurrentPage('current','navlist');"); '.
How can I append from my content page to an attribute in my master
page? so that the end result would be
<body onload='menuCurrentPage('current','navlist');");  alert('hello
world');");'>

Thanks
M.
Steve - 24 Aug 2007 19:58 GMT
Try this:

Body.Attributes("onload") += "alert('hello world');"

Steve C.
MCAD,MCSE,MCP+I,CNE,CNA,CCNA

> Hi,
>
[quoted text clipped - 18 lines]
> Thanks
> M.
mazdotnet - 24 Aug 2007 21:01 GMT
> Try this:
>
[quoted text clipped - 27 lines]
>
> - Show quoted text -

I tried it and it says
body.Attributes("onload") += "alert('hello world');";
System.Web.UI.HtmlControls.HtmlControl.Attributes' is a 'property' but
is used like a 'method'
Any idea?

Thx
AreKc - 24 Aug 2007 21:32 GMT
mazdotnet:

> I tried it and it says
> body.Attributes("onload") += "alert('hello world');";
> System.Web.UI.HtmlControls.HtmlControl.Attributes' is a 'property' but
> is used like a 'method'
> Any idea?

body.Attributes["onload"] += "alert('hello world');";

Signature

AreKc

mazdotnet - 24 Aug 2007 21:45 GMT
> mazdotnet:
>
[quoted text clipped - 8 lines]
> --
> AreKc

Still no go. In my content page I have

HtmlControl body = (HtmlControl)Master.FindControl("Body");
       body.Attributes["onload"] += "alert('hello world');";

However, on the generated page it still doesn't come up

<body id="ctl00_Body" onload="menuCurrentPage('current','navlist');">

No alert('hello world')

Anything else I could be missing

Thx
M
Mark Rae [MVP] - 24 Aug 2007 23:02 GMT
> HtmlControl body = (HtmlControl)Master.FindControl("Body");
> body.Attributes["onload"] += "alert('hello world');";

((HtmlGenericControl)Master.FindControl("Body")).Attributes["onload"] +=
"alert('hello world');";

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

chakde dotnet - 28 Aug 2007 22:27 GMT
Hi

ASP.NET would process the content page ahead of the master page. So the
code on your master page would always overwrite your onload event.

Make the following changes in your master page as below:

HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes["onload"] += "menuCurrentPage('current','navlist');";

Make the following changes in your content page as below:

HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes["onload"] += "alert('hello world');"

Your content page function will fire before your master page function
fires. Make the following changes to your master page if you want to
change the order of execution.

HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes["onload"] = "menuCurrentPage('current','navlist');" +
body.Attributes["onload"];

Thanks,
Chakde

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.