2010-04-08 23 views
1

代碼爲asp.net頁面不會工作是:主題使用服務器端代碼,當上一個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> 
<% 
    } 
%> 

爲C#文件中的代碼是:

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

請有人幫我解決.. !!

回答

3

也許你可以嘗試用另一種方式:

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

代碼隱藏:

if (CurrentUser.Role == "Free") 
{ 
    FreeHolder.Visible = true; 
} else if (CurrentUser.Role == "Pending") { 
    PendingHolder.Visible = true; 
} else if (CurrentUser.Role == "Paid") { 
    PaidHolder.Visible = true; 
} 
相關問題