开发者

"Code blocks are not supported in this context" error in ASP.NET

I am getting this error by simply trying to insert some VB.NET code in ASP.NET markup. See the code:

<%@ Control Inherits="PerformanceWeb.Framework.SiteSettings" CodeBehind="sitesettings.ascx.vb" language="vb" AutoEventWireup="false" %>

<table id="TABLE1" cellSpacing="0" cellPadding="2" border="0" runat="server">
<% If EditDowntimeMode Then%>

    <tr><td class="Normal"><asp:label id="lblDowntimeLegacyMode" Runat="server">lblDowntimeLegacyMode</asp:label></td></tr>

    <tr>
        <td class="DowntimeLegacyModeIndented" width="130">
            <asp:label id="lblLegacyMode" Runat="server">lblLegacyMode</asp:label>
        </td>
        <td class="Normal" colSpan="2">
            <asp:RadioButton id="rdoLegacyMode" GroupName="DowntimeLegacyMode" Runat="server"></asp:RadioButton>
        </td>
    </tr>
    <tr>
        <td class="DowntimeLegacyModeIndented" width="130">
            <asp:label id="lblNewCauses" Runat="server">lblNewCauses</asp:label>
        </td>
        <td class="Normal" colSpan="2">
            <asp:RadioButton id="rdoNewCauses" GroupName="DowntimeLegacyMode" Runat="server"></asp:RadioButton>
        </td>
    </tr>

    <tr>
        <td colspan="2"><hr /></td>
    </tr>

<% End if%>
</table>

Codebehind

#Region "Properties"
        Public Property EditDowntimeMode() As Bo开发者_如何学运维olean
            Get
                Return m_EditDowntimeMode
            End Get
            Set(ByVal value As Boolean)
                m_EditDowntimeMode = value
            End Set
        End Property

#End Region


When you add a runat='server' to an HTML control you change the rendering and code blocks aren't supported inside.

Changed from:

<table id="TABLE1" cellSpacing="0" cellPadding="2" border="0" runat="server">

to:

<table id="TABLE1" cellSpacing="0" cellPadding="2" border="0">


In the code behind on the Page Load, couldn't you just set the table's visible property to the negation of EditDowntimeMode ? That would seem to be a better solution than trying to mix all that markup together in what you are doing.

Something like this in the Page_Load method of the code behind:

Table1.Visible = Not EditDowntimeMode

The given example code in the question should be updated if that is the case as the example code has the if blocking out everything within the table. You could use an ASP:Panel block and control its visibility for another idea or possibly nest the tables so that an inner table could be just what the "EditDowntimeMode" would show is in its own table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜