未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll 中。错误代码如下:_header = (friendsheader)LoadControl(Request.ApplicationPath + Path.AltDirectorySeparatorChar+"contorls/friendsheader.ascx");override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//

_header = (friendsheader)LoadControl(Request.ApplicationPath + Path.AltDirectorySeparatorChar+"contorls/friendsheader.ascx");
_subheader = new SubHeader();
Page.Controls.AddAt(0,_header);
Page.Controls.AddAt(0,_subheader);
InitializeComponent();
base.OnInit(e);
}

解决方案 »

  1.   

    StackOverflowException 因执行堆栈溢出错误引发,通常在存在非常深的递归或无界递归时发生。检查一下是否存在非常深的递归或无界递归
      

  2.   

    namespace friendsreunion.contorls
    {
    using System;
    using System.Data;
    using System.ComponentModel;
    using System.Web;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
        using System.Drawing;
    using System.IO;
    using friendsreunion.contorls;
    using System.Web.UI;
    /// <summary>
    /// friendsheader 的摘要说明。
    /// </summary>
    public class friendsheader : System.Web.UI.UserControl
    {
    protected System.Web.UI.WebControls.Panel pnlHeaderGlobal;

    protected friendsreunion.SubHeader SubHeader1;
    protected System.Web.UI.WebControls.Image Image2;
    protected System.Web.UI.WebControls.Label Label1;
    protected System.Web.UI.WebControls.Label lblWelcom;
    protected System.Web.UI.WebControls.Image imgIcon;
    protected System.Web.UI.WebControls.Label lblCounter1;
    protected System.Web.UI.WebControls.Image imgShow;
    protected System.Web.UI.WebControls.DropDownList cbBackColor;
    protected System.Web.UI.WebControls.Label lblCounter;
    protected System.Web.UI.WebControls.Panel Panel2;
    private void Page_Load(object sender, System.EventArgs e)
    {
    this.lblCounter.Text = Application["counter"].ToString();
    imgShow.Attributes.Add("onclick","document.getElementByld('tbPrefs').style.display='block';");
    imgShow.Style.Add("cursor","pointer");
    if(!Page.IsPostBack)
    {
    cbBackColor.Items.Clear();
    cbBackColor.Items.Add(string.Empty);
    System.Drawing.ColorConverter cv = new ColorConverter();
    Color selected = Color.Empty;
    if(Request.Cookies["backcolor"]!=null&&Request.Cookies["backcolor"].Value!=null&&Request.Cookies["backcolor"].Value!=string.Empty)
    {
    selected = (Color)cv.ConvertFromString(Request.Cookies["backcolor"].Value);
    }
    TypeConverter.StandardValuesCollection col = cv.GetStandardValues(null);
    ListItem li;
    foreach(Color c in col)
    {
    li = new ListItem(c.Name,ColorTranslator.ToHtml(c));
    if(c.Equals(selected)) li.Selected = true;
    cbBackColor.Items.Add(li);
    }
    }
    // 在此处放置用户代码以初始化页面
    }

    private string _message = string.Empty;
    private string _imageurl = string.Empty;
    friendsheader _header;
    SubHeader _subheader;
    public string Message
    {
    get{return _message;}
    set{_message = value;}
    }
    public string IconImageUrl
    {
    get{return _imageurl;}
    set{_imageurl = value;}
    }
    protected override void Render(System.Web.UI.HtmlTextWriter writer)
    {
    Page.Controls.Remove(_header);
    Page.Controls.Remove(_subheader);
    HtmlForm form =(HtmlForm)Page.Controls[1];
    form.Controls.AddAt(0,_header);
    form.Controls.AddAt(1,_subheader);
    _header.Message = _message;
    _header.IconImageUrl = _imageurl;
    string bg = Response.Cookies["backcolor"].Value;
    if(bg == null && Request.Cookies["backcolor"]!=null&&Request.Cookies["backcolor"].Value!=null&&Request.Cookies["backcolor"].Value!=string.Empty)
    {
    bg=Request.Cookies["backcolor"].Value;
    Request.Cookies.Add(Request.Cookies["backcolor"]);
    }
    if(bg !=null&&bg !=string.Empty)
    {
    HtmlGenericControl div = new HtmlGenericControl("div");
    div.Style.Add("background-color",bg);
    Page.Controls.Remove(form);
    Page.Controls.AddAt(1,div);
    div.Controls.Add(form);
    }

    base.Render(writer);
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //

    _header = (friendsheader)LoadControl(Request.ApplicationPath + Path.AltDirectorySeparatorChar+"contorls/friendsheader.ascx");
    _subheader = new SubHeader();
    Page.Controls.AddAt(0,_header);
    Page.Controls.AddAt(0,_subheader);
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器
    /// 修改此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.cbBackColor.SelectedIndexChanged += new System.EventHandler(this.cbBackColor_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void cbBackColor_SelectedIndexChanged(object sender, System.EventArgs e)
    {
    Response.Cookies.Add(new HttpCookie("backcolor",((DropDownList)sender).SelectedItem.Value));
    }
    }
    }
    下面的是SubHeader.cs代码:
    using System;
    using System.IO;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace friendsreunion
    {
    /// <summary>
    /// SubHeader 的摘要说明。
    /// </summary>
    public class SubHeader:WebControl
    {   
    //the url to navigate to if the user is not registered
    private string _register = string.Empty;
    public SubHeader()
    {
    //
    // TODO: 在此处添加构造函数逻辑
    //
    this.Width =new Unit(100,UnitType.Percentage);
    this.CssClass="SubHeader";
    }
    //Property to allow the user to define the url for the 
    //registration page
    public string registerurl
    {
    get
    {
    return _register;
    }
    set
    {
    _register=value;
                }
    }
    //this method is called when the control is being built
    protected override void CreateChildControls()
    {
    //clear any previously load controls
        this.Controls.Clear();
    Label lbl;
    HyperLink reg= new HyperLink();
        reg.Text="Register";
    if(Context.User.Identity.IsAuthenticated)
    {
    reg.Text = "修改我的个人资料";
    reg.NavigateUrl = Context.Request.ApplicationPath
    +Path.AltDirectorySeparatorChar
    +Path.AltDirectorySeparatorChar+"NewUser.aspx";
    }
    else 
    {
    reg.Text = "Register";
        reg.NavigateUrl=_register;
    } this.Controls.AddAt(0,reg); this.Controls.Add(new LiteralControl("&nbsp;-&nbsp;")); if(Context.User.Identity.IsAuthenticated)
    {
    lbl=new Label();
    lbl.Text=Context.User.Identity.Name;
    this.Controls.Add(lbl);
    }
    lbl = new Label();
        lbl.Text = DateTime.Now.ToLongDateString();
    this.Controls.Add(lbl);
    }
    }
    }
    帮我看看哪里出错了啊~我找不到