更新时间:2022-06-18 04:57:07
Ok I got your problem,
Make sure that you Have lable control on the page with IDlblDateTime
( I think this will be. )
But The Actual Problem Here is First Your Java script event fires and you are getting Right values ( you can varify it by puttingdebugger;
to the first line of your JS Function ) to set to your label, but then page Fires server Side event and Page is Getting rendered again and Displays by default Value Applied to Lable.
[Addition to Solution]
Ok As per you Told me that you only want to fire client Side Javascript.
Ok I got your problem,
Make sure that you Have lable control on the page with IDlblDateTime
( I think this will be. )
But The Actual Problem Here is First Your Java script event fires and you are getting Right values ( you can varify it by puttingdebugger;
to the first line of your JS Function ) to set to your label, but then page Fires server Side event and Page is Getting rendered again and Displays by default Value Applied to Lable.
[Addition to Solution]
Ok As per you Told me that you only want to fire client Side Javascript.
OnClientClick="DisplayDateTime()"
OnClientClick="DisplayDateTime()"
Instead Write
Instead Write
OnClientClick = "return DisplayDateTime()"
function DisplayDateTime()
{
var DateTime = new Date();
var strYear= DateTime.getYear();
var strMonth= DateTime.getMonth() +1;
var strDay = DateTime.getDate();
var strHours = DateTime.getHours();
var strMinutes = DateTime.getMinutes();
var strSeconds = DateTime.getSeconds();
var dateTime=document.getElementById("lblDateTime");
dateTime.innerText = strDay + "/" + strMonth + "/" + strYear + " " + strHours + ":" + strMinutes + ":" + strSeconds;
}
function DisplayDateTime()
{
var DateTime = new Date();
var strYear= DateTime.getYear();
var strMonth= DateTime.getMonth() +1;
var strDay = DateTime.getDate();
var strHours = DateTime.getHours();
var strMinutes = DateTime.getMinutes();
var strSeconds = DateTime.getSeconds();
var dateTime=document.getElementById("lblDateTime");
dateTime.innerText = strDay + "/" + strMonth + "/" + strYear + " " + strHours + ":" + strMinutes + ":" + strSeconds;
}
Instead Write ( Just Appended return false to the end of function )
Instead Write ( Just Appended return false to the end of function )
function DisplayDateTime() {
var DateTime = new Date();
var strYear = DateTime.getYear();
var strMonth = DateTime.getMonth() + 1;
var strDay = DateTime.getDate();
var strHours = DateTime.getHours();
var strMinutes = DateTime.getMinutes();
var strSeconds = DateTime.getSeconds();
var dateTime = document.getElementById("lblDateTime");
dateTime.innerText = strDay + "/" + strMonth + "/" + strYear + " " + strHours + ":" + strMinutes + ":" + strSeconds;
return false;
}
Vote and Mark as a Answer if it helped.
Vote and Mark as a Answer if it helped.
Can you post your ALL code of page?
Can you post your ALL code of page?