Refer below Sample code for your reference and implement it as per your code logic.
HTML
C#
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function startTimer() {
var now = new Date();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var refreshtime = '<%=this.RefreshTime %>';
if (parseInt(refreshtime) > 0) {
setTimeout('refresh()', (((refreshtime - (minutes % refreshtime) - ((seconds > 0) ? 1 : 0)) * 60) + (60 - seconds)) * 1000);
}
}
function refresh() {
window.location.href = 'Default.aspx';
}
startTimer();
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
VB.Net
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function startTimer() {
var now = new Date();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var refreshtime = '<%= Me.RefreshTime %>';
if (parseInt(refreshtime) > 0) {
setTimeout('refresh()', (((refreshtime - (minutes % refreshtime) - ((seconds > 0) ? 1 : 0)) * 60) + (60 - seconds)) * 1000);
}
}
function refresh() {
window.location.href = 'VB.aspx';
}
startTimer();
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Code
C#
public int RefreshTime { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
// call you code to set the Property value
this.RefreshTime = GetRefreshTime();
}
}
private int GetRefreshTime()
{
int refreshTime = 0;
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
// Your Sql Query as per your logic.
string query = "select DATEDIFF(MINUTE,GETDATE(),'2018-05-03 18:00:00.000')";
SqlCommand cmd = new SqlCommand(query);
SqlConnection con = new SqlConnection(conString);
cmd.Connection = con;
con.Open();
refreshTime = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
return refreshTime;
}
VB.Net
Public Property RefreshTime As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.RefreshTime = GetRefreshTime()
End If
End Sub
Private Function GetRefreshTime() As Integer
Dim refreshTime As Integer = 0
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "select DATEDIFF(MINUTE,GETDATE(),'2018-05-03 18:00:00.000')"
Dim cmd As SqlCommand = New SqlCommand(query)
Dim con As SqlConnection = New SqlConnection(conString)
cmd.Connection = con
con.Open()
refreshTime = Convert.ToInt32(cmd.ExecuteScalar())
con.Close()
Return refreshTime
End Function