4 Replies - 2796 Views - Last Post: 13 November 2012 - 08:38 AM Rate Topic: -----

#1 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 376
  • Joined: 04-January 11

MasterPage PreInit Not Triggered

Posted 12 November 2012 - 01:22 AM

I graduated last year and landed on a good programming job. Work has been busy since I started but today I had a lot of spare time so I decided to read some articles that will help me improve my skills.

Work is done individually so I do not really get a chance to see how others do things except from my other two projects before which was turned over to me. In those projects, I got to see and understand the approach used by the previous developers.

The ASP.NET folder for App_Code is common to all the projects that I handled so I tried reading some articles about it this morning. I realized that even though I already have more than a year of experience, I am still too far from becoming a strong programmer since there are still a lot for me to know. I did not even know that there are still other ASP.NET folders besides the App_Code.

Maybe you are getting bored with my story so I'll proceed with my question. I wanted to focus on learning to use the App_Themes so I decided to try it today.

I created two themes: Blue and Green.

I created a MasterPage with a banner, content area and footer.

In the banner, there is a dropdownlist for Theme Selection and there is also a button to apply the theme selected

I placed the
Page.Theme = ddl.SelectedItem.Value;


in the MasterPage's Page_PreInit but it was never triggered... Not on first load of page and not even on the postback.

Any idea why it isn't triggered? Should I change the theme per page or can I do it in a MasterPage?

This post has been edited by November-06: 12 November 2012 - 01:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: MasterPage PreInit Not Triggered

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,212
  • Joined: 23-August 08

Re: MasterPage PreInit Not Triggered

Posted 12 November 2012 - 07:36 AM

This should be in ASP.NET.

Moved.
Was This Post Helpful? 0
  • +
  • -

#3 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: MasterPage PreInit Not Triggered

Posted 12 November 2012 - 07:49 AM

I think we'd need to see your code to be able to tell you why something isn't working the way you expect it to.
Was This Post Helpful? 0
  • +
  • -

#4 November-06  Icon User is offline

  • D.I.C Regular

Reputation: 45
  • View blog
  • Posts: 376
  • Joined: 04-January 11

Re: MasterPage PreInit Not Triggered

Posted 12 November 2012 - 06:58 PM

PreInit in MasterPage doesn't work but it works in ASP.NET pages.I override the OnPreInit
for the page and everything works.

Now I am creating a class that I can inherit for every page.

To change the theme for the whole site, I am setting the theme in web.config and everything works fine.

I just have a really simple layout so I would try to build a more complex one later.

Thanks for taking time to read and reply to this post.

I'll try to do other things too so that I can explore the other .NET functionalities.

This post has been edited by November-06: 12 November 2012 - 07:00 PM

Was This Post Helpful? 0
  • +
  • -

#5 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: MasterPage PreInit Not Triggered

Posted 13 November 2012 - 08:38 AM

View PostNovember-06, on 12 November 2012 - 05:58 PM, said:

Now I am creating a class that I can inherit for every page.


As far as I am concerned, that is a best practice. It allows you to avoid code duplication throughout your entire site (i.e. - code that gets/sets error messages).

As for your theme issue, you can use your custom Page class to set the page's theme programmatically by overriding the Page_PreInit event:
protected void Page_PreInit(object sender, EventArgs e)
{
    Page.Theme = ddlTheme.SelectedValue == "Blue" ? "Blue" : "Green";
}



You can also set the stylesheet theme by programmatically overriding the StyleSheetTheme property:
public override string StyleSheetTheme
{
  get { return ddlTheme.SelectedValue == "Blue" ? "Blue" : "Green"; }
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1