We could have instead add to the ASP page just the C# script fragment we need. If we ask to the wizard not to add a separate file for the C# code, we get a slimmer page, that we could easily modify to add our code in a specific script tag.
Here is an ASP page doing exactely the same job of the previous example:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
myTime.Text = DateTime.Now.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Hello Even Simpler</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Hello from Even Simpler. Current time is <asp:Label id="myTime" runat="server"/>
</div>
</form>
</body>
</html>
No comments:
Post a Comment