0

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>
<html>
    <head>
        <title>jClocksGMT v. 2.0</title>        
        <style>
            body { font-family: Arial, sans-serif; }
        </style>

        <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>
    </head>
    <body>
        <div id="clock_city"></div>
        <script>
            $(document).ready(

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

                }
            )
        </script>
    </body>
</html>

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?

0

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.

$('#clock_city').jClocksGMT(
  {
      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 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/… – Derek Gusoff Jan 14 at 21:59

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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