Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1018759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:54:24+00:00 2026-05-16T10:54:24+00:00

I have a designer working at the ASPX level. He doesn’t do C#, doesn’t

  • 0

I have a designer working at the ASPX level. He doesn’t do C#, doesn’t do code-behinds, doesn’t compile, etc. He’s a pure designer, working with HTML and server controls.

I need a conditional control — an If…Then-ish type thing. Normally, I would do this:

<asp:Placeholder Visible='<%# DateTime.Now.Day == 1 %>' runat="server">
  It's the first day of the month!
</asp:PlaceHolder>

Is there any way to do something like this without the databinding syntax? Something like:

<asp:If test="DateTime.Now.Day == 1" runat="server">
  It's the first day of the month!
</asp:If>

Is there some kind of way to extend a placeholder to allow this? I’ve fiddled around a bit, but in the end, I have a conditional that I essentially have to compile.

Now, there’s nothing wrong with the databinding syntax, but’s just one more bit of…weirdness, the a designer is going to have to understand. Additionally, it doesn’t give me “else” statements. Something like this would be great…

<asp:If test="DateTime.Now.Day == 1" runat="server">
  It's the first day of the month!
  <asp:Else>
    It's not the first day of the month!
  </asp:Else>
</asp:If>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:54:25+00:00Added an answer on May 16, 2026 at 10:54 am

    The data-binding syntax has two problems: first it’s a little weirder for your designer vs. using plain text, and second it requires the designer to remember to invert the “if” test in your “else” block.

    The first problem may annoy your designer a little, but the second problem is much more severe, because it forces your designer to think like a programmer (inverting boolean logic!) and makes every if/else block into a possible bug you need to test for after your designer hands over a template.

    My suggestion: use data-binding syntax, but fix the more severe problem by creating custom controls that only require data-binding test code on the If control, but not on the Else control. Sure your designers will have to type a few more characters, but the other more severe problems won’t apply and your performance won’t suffer as it would if you had to dynamically compile code each time your page ran.

    Here’s an example I coded up to illustrate:

    <%@ Page Language="C#"%>
    <%@ Register Assembly="ElseTest" TagPrefix="ElseTest" Namespace="ElseTest"%>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }
    </script>
    
    <html>
    <body>
    
        <ElseTest:IfControl runat="server" visible="<%#1 == 1 %>">
            This should be visible (in "if" area) 
        </ElseTest:IfControl>
        <ElseTest:ElseControl runat="server">
            This should not be visible (in "else" area) 
        </ElseTest:ElseControl>
    
        <br /><br />
    
        <ElseTest:IfControl runat="server" visible="<%#0 == 1 %>">
            This should not be visible (in "if" area) 
        </ElseTest:IfControl>
        <ElseTest:ElseControl runat="server">
            This should be visible (in "else" area) 
        </ElseTest:ElseControl>
    
    </body>
    </html>
    

    Here’s the underlying controls, which are simply wrappers around asp:Literal:

    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    [assembly: TagPrefix("ElseTest", "ElseTest")]
    namespace ElseTest
    {
        // simply renames a literal to allow blocks of data-bound-visibility
        [ToolboxData("<{0}:IfControl runat=\"server\"></{0}:IfControl>")]
        public class IfControl : Literal
        {
        }
    
        [ToolboxData("<{0}:ElseControl runat=\"server\"></{0}:ElseControl>")]
        public class ElseControl : Literal
        {
            public override bool Visible
            {
                get
                {
                    // find previous control (which must be an IfControl). 
                    // If it's visible, we're not (and vice versa)
                    for (int i = Parent.Controls.IndexOf(this)-1; i >= 0; i--)
                    {
                        Control c = Parent.Controls[i];
                        if (c is IfControl)
                            return !c.Visible;  // found it! render children if the if control is not visible
                        else if (c is Literal)
                        {
                            // literals with only whitespace are OK. everything else is an error between if and then
                            Literal l = c as Literal;
                            string s = l.Text.Trim();
                            if (s.Length > 0)
                                throw new ArgumentException("ElseControl must be immediately after an IfControl");
                        }
                    }
                    throw new ArgumentException("ElseControl must be immediately after an IfControl");
                }
                set
                {
                    throw new ArgumentException("Visible property of an ElseControl is read-only");
                }
            }
        }
    }
    

    If you want it more concise, you can easily shorten the tag name (by changing the class names and/or tag prefix). You can also create a new property (e.g. “test”) to use instead of “Visible”.

    If you really want to get rid of the <%# %>, there are likley many different tricks you can use to leverage CodeDOM or other ways to dynamically compile code, although performance will be a challenge since you’ll probably end up dynamically compiling code each time the page runs, it may introduce pesky security issues, and more. I’d stay away from that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 500k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Oh well i solved the problem myself. So instead to… May 16, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer Remember that binding is only refreshed when a change is… May 16, 2026 at 1:59 pm
  • Editorial Team
    Editorial Team added an answer no it's not necessary that everytime view state of a… May 16, 2026 at 1:59 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm working with the DotNetOpenAuth controls and on my ASPX pages in source view
I'm working through the ASP.NET MVC article at http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx . (Note: Some of the
ASP.NET MVC 2.0: Simple Model Binding not working/binding as it should i have a
My question is one I have pondered around when working on a demanding network
I have entity class generated by E-R designer that I have modified a little.
I have a linqtosql dbml where I dropped a stored procedure into the designer
I am working on a massive site for a client, but their current website
I have CustomForm inherited from Form which implements a boolean property named Prop .
I have been given the task of adding functionality to an existing IIS 6.0
I'm currently working on an ASP.NET 3.5 project, and I wanted to know your

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.