jgd12345:1. Place <h1><%# SiteMap.CurrentNode.Title %></h1> where i want the header in every page but this means i have to call this.DataBind() in the page load of every page i wish to have a header and this is something i don't like doing.
Why are you using the binding tags <%# %>?? just use the rendering tags <%= SiteMap.CurrentNode.Title %>, this way you don't need to call DataBind();
jgd12345:4. Place a literal within the h1 on every page and set it from within the master page. I could not get this to work. I tried doing ((Literal)this.Page.FindControl("litH1")).Text = SiteMap.CurrentNode.Title within the page load event handler of my master page but this didn't seem to do anything.
Probably because the literal is in another naming container. To solve this you can use this recursive search algorithm that i wrote to get you a reference to the specified control regardless whether the control was placed directly within the top level container or not.
simply, in ur master page write the following code:
protected void Page_Load(object sender, EventArgs e)
{
((Label)FindMyChild(this.Page.Controls, "litH1")).Text = SiteMap.CurrentNode.Title;
}
public static Control FindMyChild(ControlCollection parent, string ID)
{
Control ret = null;
foreach (Control c in parent)
{
ret = c.FindControl(ID);
if (ret != null)
break;
else
{
ret = FindMyChild(c.Controls, ID);
if (ret != null)
break;
}
}
return ret;
}
Finally, if it was me, I would have used a user control which renders the page title for the containing page and inserted that user control in every page.
Hope this helps.