Codebehind on masterpages - is it possible in umbraco 4.0?
Hi,
I am a week or so into Umbraco and has only scratched the surface.
My current project is to move a small site from Ektron cms400 to Umbraco 4. I'm almost there but ran into this in getting the site compatible with Safari.
On the old site I was using this in codebehind on my masterpages to get the asp:menu control to work right in Safari:
protectedoverridevoid AddedControl(Control control, int index)
{
if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
this.Page.ClientTarget = "uplevel";
base.AddedControl(control, index);
}
But I guess the model in umbraco is different? Is it possible to add a masterpage the 'normal' way with codebehind?
Yes, just create the template (Masterpage) from Visual Studio. That way you'll have your codebehind etc. You'll have to create a template in umbraco with the same filename before it's visible. That's the way I usually do it.
You don't need codebehind, you can add <script runat="server"> directly to masterpage, but in this particular case there is better way - add browser file, using google I found this, maybe it is not 100% correct, but it's a right way:
What I did to enable the asp:menu for Safari was to add a file called safari.browser to the App_Browsers folder. The contents of safari.browser are as follows:
Codebehind on masterpages - is it possible in umbraco 4.0?
Hi,
I am a week or so into Umbraco and has only scratched the surface.
My current project is to move a small site from Ektron cms400 to Umbraco 4. I'm almost there but ran into this in getting the site compatible with Safari.
On the old site I was using this in codebehind on my masterpages to get the asp:menu control to work right in Safari:
protected override void AddedControl(Control control, int index)
{
if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
this.Page.ClientTarget = "uplevel";
base.AddedControl(control, index);
}
But I guess the model in umbraco is different? Is it possible to add a masterpage the 'normal' way with codebehind?
Thanks
/Jesper
Yes, just create the template (Masterpage) from Visual Studio. That way you'll have your codebehind etc. You'll have to create a template in umbraco with the same filename before it's visible. That's the way I usually do it.
You don't have to create it in Visual Studio, you just need to make sure you set the Inherits statement see the MSDN overview for Master Pages - http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx
You don't need codebehind, you can add <script runat="server"> directly to masterpage, but in this particular case there is better way - add browser file, using google I found this, maybe it is not 100% correct, but it's a right way:
What I did to enable the asp:menu for Safari was to add a file called safari.browser to the App_Browsers folder. The contents of safari.browser are as follows:
<browsers>
<browser refID="safari1plus">
<controlAdapters>
<adapter controlType="System.Web.UI.WebControls.Menu" adapterType="" />
</controlAdapters>
</browser>
</browsers>
Thank you all for the responses.
I went for the VS solution and the menu is now working in Safari as well.
@petr
I could not get the safari.browser solution to work - I got to look into this a little more.
/Jesper
is working on a reply...