Mac and ASP.NET 2.0

M

mail747097

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

Mark Rae

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";
}
}
 
M

mail747097

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";
}
 
M

Mark Rae

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
}
}
 
M

mail747097

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top