vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, March 7, 2012

Solution for asp.net menu control problem in chrome browser


Recently I had faced problem asp.net menu control…Especially in chrome browser the asp.net menu control was not displaying properly...then I searched found some code would be useful to resolve my problem..
Here I share the code for those people for resolve this problem….
The below code is working perfectly for me..If you face the same problem try the below code.
Below code solve mostly solve your issues..
if Request.UserAgent.Contains("AppleWebKit") Then
      Request.Browser.Adapters.Clear()
    End If

Some other code I found when I searched….
1.
protected void Page_PreInit(object sender, EventArgs e)
         {
             // This is necessary because Safari and Chrome browsers don't display the Menu control correctly.
             if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
                 Page.ClientTarget = "uplevel";
         }
2.
protected override void AddedControl(Control control, int index)
        {
            // This is necessary because Safari and Chrome browsers don't display the Menu control correctly.
            // Add this to the code in your master page.
            if (Request.ServerVariables["http_user_agent"].IndexOf("Safari", StringComparison.CurrentCultureIgnoreCase) != -1)
                this.Page.ClientTarget = "uplevel";
                        base.AddedControl(control, index);
        }
3.
Add this below code in web.config file to solve the problems…..
<system.web>
    <browserCaps>
<case match="Chrome/(?'version'(?'major'\d+)(?'minor'\.\d+)\.\d+.\d+)\sSafari/\d+\.\d+">browser=Chrome version=${version} majorversion=${major} minorversion=${minor}</case>
    </browserCaps>
</system.web>
4.
In this method you need to create App_Browser folder in solution explorer.. Follow the below steps.
 Right click Solution explore application name and in ASP.Net folder choose App_Browser
 App_Browsers folder and then, for this, Add New Item...
Select "Browser File" and name it Chrome.browsers.
Comment out the default stuff and insert this from the link above…
<browsers>
    <browser refID="safari1plus">
      <controlAdapters>
        <adapter controlType="System.Web.UI.WebControls.Menu" adapterType="" />
      </controlAdapters>
    </browser>
  </browsers


I hop this code will be useful to all.please post your comment with the code wok for you ..It may ueful to someone…Happy coding…….

0 comments:

Post a Comment