开发者

Problem with conditional statements in asp.net

I'm trying to do the following in a aspx page:

<%@ Page Language="C#" EnableSessionSTate="true" ValidateRequest="False" Inherits="MyProject.CodeBehind.MYWF.SiteWF" MasterPageFile="~/_layouts/application.master" %>
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
    <% if (!isOld) %>
    <% { %>
        <p>display this</p>
    <% } %>

</asp:Content>

isOld is a public bool variable from the cs file mentioned in the namespace.

But unfortunately it gave me an unknown error.

I could do something similar in JSPs, but after googling around for a while, I'm not so sure whether the above is achievable in ASP.NET? (Am I missing a tag declaration, or do I have 开发者_JAVA技巧to write the entire tag lib myself?)

Thanks.

EDIT: I just got an unknown error. I have a feeling that the code above has either the wrong syntax or are totally off the wrong track. I tried the following code, and there was no error, but the bool variable is always false:

<% #if !isOld %>
    <p> display this</p>
<% #endif %>


in your code front:

<%@ Page Language="C#" EnableSessionSTate="true" ValidateRequest="False" Inherits="MyProject.CodeBehind.MYWF.SiteWF" MasterPageFile="~/_layouts/application.master" %>
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderPageDescription" runat="server">
    <asp:PlaceHolder runat="server" id="PlaceHolderIsOld">
        <p>display this</p>
    </asp:PlaceHolder>
</asp:Content>

and then in your code behind:

protected void Page_Load(object sender, EventArgs e){
   PlaceHolderIsOld.Visible = IsOld;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜