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

  • Home
  • SEARCH
  • 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 91071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:58:21+00:00 2026-05-10T22:58:21+00:00

This question is a result of what i noticed while trying to answer another

  • 0

This question is a result of what i noticed while trying to answer another question. And now im curious to know why <asp:TextBox runat='server' Visible='<%= true %>' /> leads to a compile error, and not to a visible TextBox as i would have expected.

From what i have discovered so far, the <%= %> expressions are not translated to literal controls as i have always thought. But instead it is evaluated and written directly to the HtmlTextWriter when the page is rendered. But apparently the parser (I’m unsure that is the correct term for the part that is translating ASP.NET markup to .NET code) doesn’t even attempt to evaluate <%= %> expressions, when they are used as property values for server controls. It just uses it as a string. Which i guess is why I get the error message: Cannot create an object of type ‘System.Boolean’ from its string representation ‘<%= true %>’ for the ‘Visible’ property.

If i instead ditch the runat=’server’ and combines the <%= %> with regular html-markup, like this:

<input type='button' id='Button1' visible='<%= true %>' /> 

Then the parser just splits the chunk in parts before and after the expression and then writes it to the HtmlTextWriter in the render method. Something like this:

    __w.Write('<input type=\'button\' id=\'Button1\' visible='');     __w.Write(true);     __w.Write('' />'); 

As the last thing i noticed… When i try with <%# %> + Control.DataBind(), then i get what i would expect. It hooks up the expression to be used when the control is databound, but unlike the <%= %> expression, the generated code actually evaluates the content of the <%# %> expression. The parser ends up generating the following:

[DebuggerNonUserCode] private Button __BuildControldataboundButton() {     Button button = new Button();     base.databoundButton = button;     button.ApplyStyleSheetSkin(this);     button.ID = 'databoundButton';     button.DataBinding += new EventHandler(this.__DataBindingdataboundButton);     return button; }  public void __DataBindingdataboundButton(object sender, EventArgs e) {     Button button = (Button) sender;     Page bindingContainer = (Page) button.BindingContainer;     button.Visible = true; } 

From:

<asp:Button ID='databoundButton' Visible='<%# true %>' runat='server' /> 

Notice the button.Visible = true; that is the result of the <%# %> expression.

So my question is.. Why is the expression in the first example just treated as a string, instead of being evaluated to ‘true’. The expressions is somewhat similar for the two other examples, and they yield the code i would have expected.

Is it just a mistake (which i doubt since it isn’t a new issue with the current version of ASP.NET), or is there a good reason why we are not allowed to use <%= %> like that?

  • 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. 2026-05-10T22:58:21+00:00Added an answer on May 10, 2026 at 10:58 pm

    This:

    <asp:Button runat='server' id='Button1' visible='<%= true %>' /> 

    Does not evaluate to this:

    <asp:Button runat='server' id='Button1' visible='true' /> 

    <%= %> outputs directly to the response stream, and the asp markup is not part of the response stream. Its a mistake to assume the <%= %> operators are performing any kind of preprocessing on the asp markup.


    As an aside, it helps to think about the ASP.NET lifecycle with respect to the <%# %> and <%= %> operators.

    • <%# %> has semantics more in common with assigning a value to an object. In the ASP.NET lifecycle, the <%# %> operators are evaluated before the page writes the first byte to the response buffer.

    • <%= %> means the same thing as Response.Write. We need to perform all of our databinding and form processing first, and output HTML to the response buffer at the very end of the ASP.NET lifecycle.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer First, change the image resolution to 96DPI, this can done… May 11, 2026 at 12:05 pm
  • added an answer <xsl:value-of select='*[local-name() = $MyAttributeValue]' /> will return each child element… May 11, 2026 at 12:05 pm
  • added an answer Try removing the Klokke property from the UIKlokke control and… May 11, 2026 at 12:05 pm

Related Questions

This question is a result of what i noticed while trying to answer another
This question is a follow up to my previous question about getting the HTML
This question is a follow up on one of my other questions, Can I
This question is a follow-up from How to indicate that a method was unsuccessful
This question is a follow up to: Why can’t I call a method outside
I suppose this question is a variation on a theme , but different. Torrents
This question is for a web application. And maybe it's a stupid question but
This question is about a Java JTree or a Window .Net Tree (Winforms) or
This question is about a whole class of similar problems, but I'll ask it
This question is inspired by Jon Skeet's answer: Is there a c# equivalent to

Trending Tags

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

Top Members

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.