default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" Theme="Blue" %>
<%@ Register TagPrefix="uc1" TagName="favicon" Src="~/FavIcon.ascx" %>
<!DOCTYPE html>
<script runat="server">
private void Page_PreRender(object sender, System.EventArgs e)
{
HtmlGenericControl scriptControl = new HtmlGenericControl("script");
Page.Header.Controls.AddAt(0, scriptControl);//If this line is commented out, no exception will occur.
}
private void Page_Init(object sender, System.EventArgs e)
{
ScriptManager oSM = new ScriptManager();
Page.Form.Controls.Add(oSM);//If this line is commented out, no exception will occur.
}
</script>
<html>
<head runat="server">
<title></title>
<uc1:favicon runat="server"></uc1:favicon>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
</form>
</body>
</html>
FavIcon.ascx
<%@ Control Language="C#" ClassName="FavIcon" AutoEventWireup="true" %>
<script runat="server">
void Page_Load(object sender, EventArgs e)
{
this.Visible = false;//If this line is commented out, no exception will occur.
}
</script>
Also add a stylesheet to the Blue theme.
The page opens successfully, but once I click the button, it throws exception
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
Can anyone explain why this error happens?
