Reputation: 75
This is the code I made before I realized that the Calender control exists. And please never mind the typo [canlender]!
Somehow this code is making the state of whole IIS [Service Unavailable]. Doing net stop w3svc / net start w3svc won't work too. The hosting provider said [What have you done?]. On my computer (IIS on Win8) would freeze too.
I don't find anything that would make the server unable to service. It's just creating and modifying controls... Any idea about the cause of this problem?
Thanks.
calender.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);
}
}
}
calender.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>
Upvotes: 2
Views: 115
Reputation: 3315
tc.Controls.Add(tc);
are you sure this is intended? it seems like a circular reference.
Upvotes: 1