2010-04-08 3 views
1

Le code de la page asp.net est:Thèmes ne fonctionnera pas lorsque vous utilisez Tags côté serveur sur une page ASP.NET

<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> 
<% 
    } 
%> 

Le code pour le fichier C# est:

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; 
} 

le code donne l'erreur suivante:

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 

S'il vous plaît quelqu'un m'aider .. !!

Répondre

3

Peut-être que vous pouvez essayer d'une autre manière:

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; 
} 
Questions connexes