两种方法可以实现
1.客户端:
<script language="javascript" type="text/javascript">
window.onload=function getTime()
{
var date = new Date(); //日期对象
var now = "";
now = date.getFullYear()+"-"; //读英文就行了
now = now + (date.getMonth()+1)+"-"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
now = now + date.getDate();
document.getElementById("txtAddDate").value=now;
}
</script>
2.服务器端:
protected override void Render(HtmlTextWriter writer)
{
//继承模板页的内容页加入 onload 事件
System.IO.StringWriter sw = new System.IO.StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
base.Render(htw);
writer.Write(sw.ToString().Replace("<body", "<body onload=javascript:alert('欢迎光临!');"));
}