2

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>

1 Answer 1

1
tc.Controls.Add(tc);

are you sure this is intended? it seems like a circular reference.

Sign up to request clarification or add additional context in comments.

4 Comments

Looks like the IIS is resulting the right error this time. Thank you! ...but the oddness of IIS being frozen after doing this reference... can it be considered as a bug of the server software?
I guess you could consider it a bug but tbh i wouldn't expect iis to handle this situation differently. It's probably causing a stack overflow because everytime the html for var TC is created the parser will continue with it's child element TC. That can't go on forever :)
Yeah... I'd liked if ASP.net would have shown the stack overflow error. Thanks for the advice!
stack overflows and thread exceptions are on my list of unloggable exceptions so i completely aggree that i would like them to be loggable :) ! You're welcome & good luck with the project !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.