Mac and ASP.NET 2.0

  • Thread starter Thread starter mail747097
  • Start date Start date
M

mail747097

How do I get ASP.NET 2.0 to treat Safari on Mac as a browser that can
handle for example Javascript?
 
How do I get ASP.NET 2.0 to treat Safari on Mac as a browser that can
handle for example Javascript?

private void Page_PreInit(object sender, EventArgs e)
{
if (Request.Browser.Browser.Contains("Safari"))
{
ClientTarget = "uplevel";
}
}
 
private void Page_PreInit(object sender, EventArgs e)
{
if (Request.Browser.Browser.Contains("Safari"))
{
ClientTarget = "uplevel";
}



}- Dölj citerad text -

- Visa citerad text -

I think it is strange that if I add the code below to my MasterPage so
ASP.NET should consider everything as a high level the menu control
stil does not work on Safari. It only works if the browser
identification in Safari is changed. I have also tested with
Konqureror on Linux that have the same behaviour and it works as
expected with the code below.

protected void Page_Init(object sender, EventArgs e)
{
Page.ClientTarget = "uplevel";
}
 
I think it is strange that if I add the code below to my MasterPage so
ASP.NET should consider everything as a high level the menu control
stil does not work on Safari. It only works if the browser
identification in Safari is changed. I have also tested with
Konqureror on Linux that have the same behaviour and it works as
expected with the code below.

protected void Page_Init(object sender, EventArgs e)
{
Page.ClientTarget = "uplevel";
}

Not strange at all - please re-read my reply...

The ClientTarget property needs to be set in Page_PreInit, not Page_Init...
Since MasterPages are UserControls, not actual aspx pages, they don't have a
PreInit method, so you can't set the ClientTarget in your MasterPage...

Therefore, you have two choices:

1) add the code above to the Page_PreInit method of every aspx page

2) create a separate page template class and inherit all your other pages
from it

using System;

public class BaseMasterEvents : System.Web.UI.Page
{
public BaseMasterEvents()
{
this.PreInit += new EventHandler(BaseMaster_PreInit);
}

private void BaseMaster_PreInit(object sender, EventArgs e)
{
if (Request.Browser.Browser.Contains("Safari"))
{
this.ClientTarget = "uplevel";
}
}
}

public partial class MyASPXPage : BaseMasterEvents
{
private void Page_Load(object sender, System.EventArgs e)
{
// regular page_load stuff
}
}
 
Not strange at all - please re-read my reply...

The ClientTarget property needs to be set in Page_PreInit, not Page_Init....
Since MasterPages are UserControls, not actual aspx pages, they don't have a
PreInit method, so you can't set the ClientTarget in your MasterPage...

Therefore, you have two choices:

1) add the code above to the Page_PreInit method of every aspx page

2) create a separate page template class and inherit all your other pages
from it

using System;

public class BaseMasterEvents : System.Web.UI.Page
{
public BaseMasterEvents()
{
this.PreInit += new EventHandler(BaseMaster_PreInit);
}

private void BaseMaster_PreInit(object sender, EventArgs e)
{
if (Request.Browser.Browser.Contains("Safari"))
{
this.ClientTarget = "uplevel";
}
}

}

public partial class MyASPXPage : BaseMasterEvents
{
private void Page_Load(object sender, System.EventArgs e)
{
// regular page_load stuff
}



}- Dölj citerad text -

- Visa citerad text -- Dölj citerad text -

- Visa citerad text -

Thanks for sorting that out. It works great now that I have moved the
code to the PreInit event in a base class for all pages.
 
Back
Top