Finding local browser time in ASP.NET

How to find out the local time for a user viewing your site in ASP.NET?

+3
source share
2 answers

Create a hidden input control to return the value on the server the next postback on the next page. It will need to be populated in the onload event for the page with the value of the new Date object created in JavaScript. You will want to create a JavaScript function for this and add it to the page using RegisterClientScriptBlock.

Something like that;

function setNow(hiddenInputId)
{
     var now = new Date();
     var input = document.getElementById(hiddenInputId);

     if(input) input.value = now.toString();
}

Then create a function call passing the ClientId to the hidden input, and then add this part of the script to the page using RegisterStartupScript so that it runs when the page loads.

+5

JavaScript , . , querystring, AJAX.

+1

Source: https://habr.com/ru/post/1698630/


All Articles