Body.Attributes.Add

  • Thread starter Thread starter mazdotnet
  • Start date Start date
M

mazdotnet

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.
 
Try this:

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


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

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

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








- 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
 
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');";
 
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');";

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
 
HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes["onload"] += "alert('hello world');";

((HtmlGenericControl)Master.FindControl("Body")).Attributes["onload"] +=
"alert('hello world');";
 
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
 
Back
Top