views:

86

answers:

1

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..!!

+1  A: 

Maybe you can try in another way:

Aspx:

<asp:PlaceHolder runat="server" ID="FreeHolder" Visible="false">
    <table> ... </table>
</asp:PlaceHolder>
<asp:PlaceHolder runat="server" ID="PendingHolder" Visible="false">
  <p style="text-align:justify;">
    Your Request is pending with our Administrators. ...
  </p>
</asp:PlaceHolder/>
<asp:PlaceHolder runat="server" ID="PaidHolder" Visible="false">
...
</asp:PlaceHolder/>

Code-Behind:

if (CurrentUser.Role == "Free")
{
    FreeHolder.Visible = true;
} else if (CurrentUser.Role == "Pending") {
    PendingHolder.Visible = true;
} else if (CurrentUser.Role == "Paid") {
    PaidHolder.Visible = true;
}
Dylan Lin