Thursday, February 25, 2010

Get ASP.NET Menu work on Chrome, Safari and Opera

I have done some research on this, i found couple of interesting solutions. Actually the are cracks to get Menu working

Solution 1:

// For Cross Browser Compatibility (Safari/Chrome) 
       if (Request.UserAgent.IndexOf("AppleWebKit") > 0) 
       { 
           Request.Browser.Adapters.Clear(); 
       }


I have added this code in master page. I Worked when there is no master page. But when there is a master page its not working for the first time so found below code which works with master page.



Solution 2:



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); 
  }


The reason i added it in the AddedControl method was so that i didn't have to use a basepage or parent class that every single aspx file had to inherit. And its the only method that i found to run before the Page_PreInit. Hope it works for you too!

No comments:

Post a Comment