Themes wont work when using Server Side Tags on an ASP.NET Page
Posted
by Sumit Sharma
on Stack Overflow
See other posts from Stack Overflow
or by Sumit Sharma
Published on 2010-04-08T01:23:58Z
Indexed on
2010/04/08
1:33 UTC
Read the original article
Hit count: 438
The code for the asp.net page is:
<div class="facebox_content">
<% if (CurrentUser.Role == "Free")
{
%>
<table cellpadding="0" cellspacing="0" style="border-collapse:collapse;width:380px;">
<tr>
<td>
User Name :
</td>
<td>
Membership Cost :
</td>
</tr>
<tr>
<td style="width:190px;">
<asp:TextBox ID="txtUserName" Enabled="false" runat="server" Text="<%= CurrentUser.Name %>"/>
</td>
<td style="width:190px;">
<asp:TextBox ID="txtCost" Enabled="false" runat="server" Text="2000"/>
</td>
</tr>
<tr>
<td>
<br />
Cheque / Draft No.:
</td>
<td>
<br />
Bank Drawn On :
</td>
</tr>
<tr>
<td style="width:190px;">
<asp:TextBox ID="txtChqNo" runat="server"></asp:TextBox>
</td>
<td style="width:190px;">
<asp:TextBox ID="txtBankName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<br />
Date :
</td>
<td>
<br />
City :
</td>
</tr>
<tr>
<td style="width:190px;">
<asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
</td>
<td style="width:190px;">
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
</td>
</tr>
</table>
<%
}
else if(CurrentUser.Role == "Pending")
{
%>
<p style="text-align:justify;">
Your Request is pending with our Administrators.
Please be patient while your request is processed.
Usually it takes 2-4 Days for your request to be processed after the payment has been received.
</p>
<%
}
else if(CurrentUser.Role == "Paid")
{
%>
<p style="text-align:justify;">
You are already a Paid Member of Website
</p>
<%
}
%>
The code for the C# file is:
protected void Page_PreInit(object sender, EventArgs e)
{
this.Theme = CurrentUser.Theme;
}
protected void Page_Load(object sender, EventArgs e)
{
txtUserName.Text = CurrentUser.Name;
ConfirmButton.Attributes.Add("onclick", "javascript:document.getElementById('" + lblMsg.ClientID + "').style.display='none';");
if (CurrentUser.Role != "Free")
ConfirmButton.Visible = false;
}
The code is giving the following error:
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.Add(Control child) +8678903
System.Web.UI.PageTheme.SetStyleSheet() +478
System.Web.UI.Page.OnInit(EventArgs e) +8699660
System.Web.UI.Control.InitRecursive(Control namingContainer) +333
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378
Please some one help me out..!!
© Stack Overflow or respective owner