学院首页>网络编程>ASP>利用服务器端控制向TextBox中载入数据(时间和日期)

利用服务器端控制向TextBox中载入数据(时间和日期)

作者:未知 来源:aspfree.com 添加时间:2006-5-21 10:26:56
导 读:一段简单的在WEB控件上显示时间的代码。 
--------------------------------------------------------------------------------
This code tip  demonstrates how to display a date in a textbox Server 
Control when the form loads.  Many of the form textbox's have a 
default DATE value displayed on Form load.  This particular example
shows how to display the System date in mm/dd/yyyy format minus seven 
days.

Here is the code.

<%@ Import Namespace="System" %>
<script language="vb" runat="server">

Sub Page_load(src As System.Object, E As System.EventArgs)

Dim NewTime as DateTime
NewTime = DateTime.Now.Subtract(New TimeSpan(7, 0, 0, 0))

'Do the label control
MyTimeControl.Text = NewTime.ToShortDateString()

'Do the textbox control
MyTimeControl2.Text = NewTime.ToShortTimeString()

End Sub
</script>

<html>
<head>
<title>Untitled</title>
</head>

<body>
<form method="post" runat="server">
  <asp:label id="MyTimeControl" runat=server/>
  <asp:textbox id="MyTimeControl2" runat=server/>
</form> 

</body>
</html> 
站内搜索