Showing posts with label header. Show all posts
Showing posts with label header. Show all posts

Thursday, March 22, 2012

Set Header Title from within a normal object

Is it possible to set the title for a page within a normal object; e.g.

1using System;
2using System.Web;
3using System.Web.UI;
4using System.Collections;
5using System.Web.UI.WebControls;
6using System.Web.UI.HtmlControls;
78namespace Utils
9{
10// Program start class11public class Misc
12 {
13public static void setSubject(Page page, String subject) {
14 page.Header.Title=subject;
15 }
16}

Compiling it gives me following error:

Utils.cs(16,4): error CS0117: `System.Web.UI.Page' does not contain a definition for `Header' Compilation failed: 1 error(s), 0 warnings

Thanks in advance,

jerous.

isn't it just Page.Title?

You'll need to ensure that the calling page has the runat="server" in it's <title..> tag.


Use page.Title property. It would set your page Title.

Set Masterpage Image...

Hi Y'all,

I want to set an image (header) in my masterpage, i don't want to use design view because the image can change.

It works like this:

1protected void Page_Load(object sender, EventArgs e)2 {3//change the image4System.Web.UI.WebControls.Image masterImage;5masterImage = (System.Web.UI.WebControls.Image)6Master.FindControl("tssclogo");7if (masterImage !=null)8 {9 Session["masterpageurl"] ="~/img/logo.gif";10 masterImage.ImageUrl = Session["masterpageurl"].ToString();11 }12 }

But the problem is that i have to put this code in every page load of my content pages. Isn't there a way i only have to set this once?

Thanks in advance!

Why don't you use an usercontrol. Put that on the masterpage and let that handle the image...
It slipped my mind... but why not using the onload event of the masterpage itself?

that's a nice idea!

I will have to work with 2 masterpages then because the userid only gets determined after authentication.

Thanks


You can work with one. Just check in the onpageload if the user is authenticated. If not, get the default image, otherwise the non-default...