Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why date format changes itself when change the browser?

Tags:

date

c#

asp.net

I have a gridview on my form. I am binding it with same data. There is a template field, which I mentioned below.

<asp:TemplateField HeaderText="To">
    <itemtemplate>
    <asp:Label ID="Label2" runat="server" 
         Text='<%# Convert.ToDateTime(Eval("Leave_To")).ToString("dd/MM/yyyy") %>'></asp:Label>
    </itemtemplate>
    <headerstyle horizontalalign="Left" />
    <itemstyle horizontalalign="Left" />
</asp:TemplateField>

My issue is that when I run this form on Mozilla, Opera, Chrome etc. it shows the date format (with oblique) dd/mm/yyyy, but when I run it with ie 10 it shows format (with hyphen) dd-mm-yyyy. why?

Can anyone help on this ?

like image 595
Rahul Sutar Avatar asked Jan 15 '15 07:01

Rahul Sutar


1 Answers

I can't test it right now, but I guess the IE is sending a "Accept-Language" header in the request, that is different of your current culture. Thus, it is overriding the current culture of the application (Culture of the WebServer/IIS)...

Try to set this on your Web.config:

 <configuration>
    <system.web>
       <globalization culture="en-GB" uiCulture="en-GB" />
    </system.web>
 </configuration>

Set your desired culture inside the principal key. (But the culture "en-GB" already provides the desired date format).

Hope I helped...

like image 71
Vitox Avatar answered Nov 03 '22 05:11

Vitox