I currently have a visual web part that displays clocks from different time zones, using the jClocksGMT library as provided here in the .ascx file. However, instead of hardcoding the timezones I want to be able to pass the correct GMT values from the .ascx.cs file and have the clocks update accordingly. However I can't seem to find a straight answer for how to do this. How is it done?

Here is an example of the code from my .ascx file:

<!doctype html>
        <title>jClocksGMT v. 2.0</title>        
            body { font-family: Arial, sans-serif; }

        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        <link rel="stylesheet" href="http://dev/Style%20Library/jClocksGMT-master/css/jclocksGMT.css"/>
        <script type="text/css" src="http://dev/Style%20Library/jClocksGMT-master/css/jClocksGMT.css"></script>
        <script type="text/javascript" src="http://dev/Style%20Library/jClocksGMT-master/js/jClocksGMT.js"></script>
        <script type="text/javascript" src="http://dev/Style%20Library/jClocksGMT-master/js/jquery.rotate.js"></script>
        <div id="clock_city"></div>

                function () {
                        title: 'City, USA',
                        offset: '-7' // <-- Value I want to change via .ascx.cs file
                        //imgpath: 'http://dev/Style Library/jClockGMT-master/'


Edit: What I mean is that I do not know how to update the values via client-side. Once I have the correct offset value in the .ascx.cs file, how do I get it into the client-side jQuery?

1 Answer 1


If you can't easily grab the offset via client side, use a hidden field on the web part and populate it in C#. Then in client side code, grab the value of that field via jQuery and use it to power the jClocksGMT call.

      title: 'City, USA',
      offset: $("#lblTimeZone").text()
      //imgpath: 'http://dev/Style Library/jClockGMT-master/'
  • Do you mean adding a Label to the web part and picking it up with the ascx.cs file, or something different? When I add a Label edit it with the .ascx.cs file the jQuery doesn't seem to pick anything up and the "offset" field is blank.
    – gsamerica
    Jan 14, 2019 at 20:18
  • a Label will work but there's also a HiddenField object for just this purpose. You'll hve the figure ou the jQuery selector for that but it'll be there. docs.microsoft.com/en-us/dotnet/api/… Jan 14, 2019 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.