这是我在意识到 Calender 控件存在之前编写的代码。请不要介意错字[canlender]!
不知何故,这段代码使整个 IIS [服务不可用] 的状态。做 net stop w3svc / net start w3svc 也行不通。托管服务提供商说[你做了什么?]。在我的计算机上(Win8 上的 IIS)也会冻结。
我没有发现任何会使服务器无法服务的东西。它只是创建和修改控件...有关此问题的原因的任何想法?
谢谢。
日历.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class member_Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
int currday = 1;
int len = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
switch (new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).DayOfWeek) {
case DayOfWeek.Sunday: currday = 1; break;
case DayOfWeek.Monday: currday = 0; break;
case DayOfWeek.Tuesday: currday = -1; break;
case DayOfWeek.Wednesday: currday = -2; break;
case DayOfWeek.Thursday: currday = -3; break;
case DayOfWeek.Friday: currday = -4; break;
case DayOfWeek.Saturday: currday = -5; break;
}
TableRow tr = new TableRow();
TableHeaderCell tst;
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Sun"; tr.Controls.Add(tst);
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Mon"; tr.Controls.Add(tst);
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Tue"; tr.Controls.Add(tst);
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Wed"; tr.Controls.Add(tst);
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Thu"; tr.Controls.Add(tst);
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Fri"; tr.Controls.Add(tst);
tst = new TableHeaderCell(); tst.CssClass = "single_day"; tst.Text = "Sat"; tr.Controls.Add(tst);
tblCanlender.Controls.Add(tr);
int a=0;
while (currday <= len && a++<50)
{
tr=new TableRow();
for (int i = 0; i < 7; i++) {
TableCell tc = new TableCell();
if (currday >= 1 && currday <= len) {
tc.CssClass = "single_day_body";
tc.Text = currday.ToString();
tc.Controls.Add(tc);
LinkButton lnk = new LinkButton();
lnk.Text = "Add";
tc.Controls.Add(lnk);
}
tr.Controls.Add(tc);
currday++;
}
tblCanlender.Controls.Add(tr);
}
}
}
日历.aspx
<%@ Page Language="C#" EnableViewState ="false" AutoEventWireup="true" CodeFile="calender.aspx.cs" Inherits="member_Default" %>
<style type="text/css">
.single_day{
width:80px;
height:40px;
background:#DDD;
}
.single_day_body{
width:80px;
height:80px;
text-align:left;
vertical-align:top;
background:#FFF;
}
table, th, tr, td, thead, tbody {
border: 0;
margin: 0;
padding: 0;
}
a.insertdate, a.insertdate:visited, a.insertdate:link {
color:gray;
text-decoration:none;
}
a.insertdate:hover {
color:#DDD;
}
</style>
<asp:Table runat="server" id="tblCanlender" style="width:100%;border:1px solid gray;background:#EEE"></asp:table>