title: How to get timezone before postback
body: <p>I am making a page that accepts post data from any number of pages that I cannot change, access, or in any way control.</p>
  
  <p>I need, in one way or another, to get the timezone of the user. I know, ideally the posting page would do this, but I cannot access these pages.</p>
  
  <p>I've read other answers on this site and come up with 2 almost, but not quite there solutions.</p>
  
  <p>First, there is javascript. I can get the javascript function to return (or change a label to) the correct value, but the problem is I need this info before the postback. I've been trying to write the timezone name on another page and read that page, but I have no idea how to begin to do that? Any other workaround to use the javascript is welcome, or any way to force call this before Page_Load is called?</p>
  
  <pre><code>    function getTimeZone()
      {
         var d = new Date()
         var gmtHours = -d.getTimezoneOffset()/60;
         var label = document.getElementById("&lt;%=TZ.ClientID%&gt;");
         label.textContent = "GMT " + gmtHours;
      }
  </code></pre>
  
  <p>The second solution is to read it from another page, and I am using this: </p>
  
  <pre><code>http://ipinfodb.com/ip_query.php?ip=192.36.167.120&amp;timezone=true
  </code></pre>
  
  <p>(Completely random ip in there, btw)</p>
  
  <p>So here is my function to get the info from that site:</p>
  
  <pre><code>        public string GetTimezone(string ip)
      {
          string address = string.Format("http://ipinfodb.com/ip_query.php?ip={0}&amp;timezone=true", ip);
          string timezone = "";
  
          try
          {
              XmlTextReader reader = new XmlTextReader(address);
              HttpWebRequest wrq = (HttpWebRequest)WebRequest.Create(address);
              wrq.Proxy.Credentials = CredentialCache.DefaultCredentials;
              reader = new XmlTextReader(wrq.GetResponse().GetResponseStream());
  
              string lastRead = "";
              while (reader.Read())
              {
                  if (reader.NodeType == XmlNodeType.Element)
                  {
                      lastRead = reader.Name;
                  }
                  if (reader.NodeType == XmlNodeType.Text)
                  {
                      if (string.Compare(lastRead, "TimezoneName", true) == 0)
                      {
                          timezone = reader.Value;
                          break;
                      }
                  }
              }
          }
          catch
          {
              timezone = "";
          }
  
          return timezone;
      }
  </code></pre>
  
  <p>Basically, this works in debug mode, but when it's live only an empty string is returned. I am baffled? Is there any better way to read data from a page? I am using Request.ServerVariables["REMOTE_ADDR"] to get the ip, and that seems to be correct, since it inserts the correct ip into the database I'm using.</p>
  
  <p>Here is the call:</p>
  
  <pre><code>GetTimezone(Request.ServerVariables["REMOTE_ADDR"]);
  </code></pre>