Showing posts with label masterpage. Show all posts
Showing posts with label masterpage. Show all posts

Thursday, March 29, 2012

set control on masterpage

Is it possible to set a control on the masterpage from a content page.
Or can you only place stuff in the contentplace holder.
f.e i want to place a label on the masterpage.
and put info in it from a contentpage created from the masterpage
thanxI don't think so and probably this violates the benefit of master pages.
Hi,

Pirate: This can be useful if you have a label on your page and want to change it to reflect what is in your content and I don't see a problem with this myself but my ears are always open to suggestions...

spoofer: You can do it like this...
In your master page define a property public string setLabel
{
set { this.lblTitle.Text = value; }
get { return this.lblTitle.Text; }
}

Then in your content page at the top of the .aspx<%@. MasterType VirtualPath="~/base.master" %>
and in your content page codebehindthis.Master.setLabel = "This is new label";
I'm just following what's called 'best practice' from MS... :p.I've not seen anyone doing it this way.It could be right but rarely used!
Thanx Fishcake, just what i was looking for!
Example + Demo

here:
http://www.geula.biz/works/sample/asp%20net/addControlFromTheContentToTheMaster.aspx
I'm just following what's called 'best practice' from MS... :p.I've not seen anyone doing it this way.It could be right but rarely used!
Not necessarily 'best', then.

There are certain dependencies that do arise in some applications, because a Master Page cannot necessarily be so static. It's also why Master Pages are actually controls that are injected into a page that 'uses' the master page.

Thursday, March 22, 2012

set masterpage for browser in web.config (.net2.0)

Hi,
it is possible to set the browser dependent masterpage in the web.config,
and how?
in the page attributes it is an easy way, but in the web.config?
In the page-tag it would look like this:
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" ie:MasterPageFile="~/MasterPage_IE.master"
mozilla:MasterPageFile="~/MasterPage_Firefox.master" %>
Thanks a lot,
Alex<configuration>
<system.Web>
<pages master="default.master" />
</system.Web>
</configuration>
Ashok
"Alexander Widera"
<awid@.hrz.tu-chemnitz.de-novaliddomainpleasedeletethispart.de> wrote in
message news:OZ4GZEBBGHA.3536@.TK2MSFTNGP11.phx.gbl...
> Hi,
> it is possible to set the browser dependent masterpage in the web.config,
> and how?
> in the page attributes it is an easy way, but in the web.config?
> In the page-tag it would look like this:
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
> Inherits="_Default" ie:MasterPageFile="~/MasterPage_IE.master"
> mozilla:MasterPageFile="~/MasterPage_Firefox.master" %>
>
> Thanks a lot,
> Alex
>
>
this is for the "default" browser...
but how to set special masterpages for different browsers (in the
web.config)?
In the page tag it looks like that (see below)... but in the web.config
...
i dont now how...
<%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" ie:MasterPageFile="~/MasterPage_IE.master"
mozilla:MasterPageFile="~/MasterPage_Firefox.master" %>
alex
"Showjumper" <dfgkjhdf> schrieb im Newsbeitrag
news:e3aiMiBBGHA.4092@.TK2MSFTNGP09.phx.gbl...
> <configuration>
> <system.Web>
> <pages master="default.master" />
> </system.Web>
> </configuration>
> Ashok
> "Alexander Widera"
> <awid@.hrz.tu-chemnitz.de-novaliddomainpleasedeletethispart.de> wrote in
> message news:OZ4GZEBBGHA.3536@.TK2MSFTNGP11.phx.gbl...
web.config,
CodeFile="Default.aspx.cs"
>
>
hasn't anybody a solution?
"Alexander Widera"
<awid@.hrz.tu-chemnitz.de-novaliddomainpleasedeletethispart.de> schrieb im
Newsbeitrag news:%23dQzXgHBGHA.2708@.TK2MSFTNGP12.phx.gbl...
> this is for the "default" browser...
> but how to set special masterpages for different browsers (in the
> web.config)?
> In the page tag it looks like that (see below)... but in the web.config
> ...
> i dont now how...
> <%@. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
> Inherits="_Default" ie:MasterPageFile="~/MasterPage_IE.master"
> mozilla:MasterPageFile="~/MasterPage_Firefox.master" %>
> alex
>
>
> "Showjumper" <dfgkjhdf> schrieb im Newsbeitrag
> news:e3aiMiBBGHA.4092@.TK2MSFTNGP09.phx.gbl...
> web.config,
> CodeFile="Default.aspx.cs"
>
>

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...

Tuesday, March 13, 2012

Set properties on masterpage declaratively

Hi, is it possible to do this?

So you'd set a property on the master page in the aspx.

If by declaratively you mean programmatically, yes you can. Take a look at my example

I created a MasterPage, called BasePage.master, and added the following code to its code-behind:

public partialclass BasePage: System.Web.UI.MasterPage{private int magicNumber;public int MagicNumber {get {return magicNumber; }set { magicNumber =value; } }protected void Page_Load(object sender, EventArgs e) { }}

Then I created a new Web Form (.aspx) page, called Test.aspx, and picked Base.master to be its MasterPage. I also added the following line to .aspx page:

<%@. MasterType VirtualPath="~/BasePage.master" %>

Using the MasterType directive allows the .aspx page to access the public properties and fields of the MasterPage via the Master property. The following code is from the code-behind of Test.aspx, take a look:

public partialclass Test : System.Web.UI.Page{protected void Page_Load(object sender, EventArgs e) { Master.MagicNumber = 2007; }}

Hope this helps.


Hi there, I appreciate your effort but since when has doing something declaratively ever meant writing code in a code behind file?? I mean, isn't the whole point of the word 'declarative' to indicate the absence of code?


Hi,

Your original question wasn't clear, as in you didn't say whether or not you had created the property on the Master page or not. Don't scold someone for trying to help you!

If you just need to set an existing property on the master page declaratively, then use the following code (for a string property):

<%Page.Master.MyProperty = "MyValue"%>

Of course though, if the property doesn't already exist on the Master Page, then youMUST write code to create it! For this, refer to the above post for instructions.

Rich


Yes my question was not that clear.

<%Page.Master.MyProperty = "MyValue"%>

The trouble with this is that its a render block so its not going to be set until the end of the page life cycle. I want to set the value of properties on the master page as if the master page was a user control contained by the page and the assignments are within the user control's tag.

Cheers, WT.


Hi,

Now I see what you mean! I don't think there is a way to do this directly. You are gonna have to write some code initially, but you should be able to reuse it on all pages using the same Master Page. The way I would do it would be to create a User Control and:

Expose a public property on the User Control, taking the value of the property you wish to set.