Hints And Tips research knowledge archive
Tip# 456
Sponsored Links
 
Subject: Easy Fix for "server tags cannot contain <% ...%> contructs!
Updated: Jan-17-2007
Rating: Not Rated
By: Rocky Moore - Member #: 461
Location: Klamath Falls, Oregon USA
Website: www.ReflectedThought.com
Category: Computers > Programming > .NET > ASP.NET
Rate This Tip (10=Great):  1  2  3  4  5  6  7  8  9  10
Every now and then I will have a server control that I need to include a value generated from code inside a field on the control.  For example:

<asp:label id="myname" runat="server" text="<% CurrentUserName %>" />

That will shoot out the all too common ASP.NET "server tags cannot contain <% ...%>" error message.

I found this article on using a custom ExpressionBuilder to make it easy to access data fetched from code inside these fields:

http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-CodeExpressionBuilder.aspx

The solution from the article is a simple class:

[ExpressionPrefix("Code")]public class CodeExpressionBuilder : ExpressionBuilder 
{    
   public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,   object parsedData, ExpressionBuilderContext context) 
   {        
           return new CodeSnippetExpression(entry.Expression);    
   }
}


and map that into your web.config file under ExpressionBuilders.  After that you can use code such as:

<asp:label id="myname" runat="server" text="<% Code: CurrentUserName %>" />

Pretty slick!  Be sure to check the article for more information on the process!

[Submit DIGG for this tip]


-----------
Note: Use the tips posted on this site at your own risk. The tips are posted by the public and as such may or may not be valid.

Sponsored Links
     
Categories
hints and tips gold divider
Sponsor Sites To Visit
www.SaintsInLight.com
Thoughts on the Christian walk
along various Christian links.

CICK HERE
www.BringingInTheHarvest.com
Christian:  The harvest is ripe and
the day is short, we need to bring in
the harvest while there is time!

CLICK HERE
XML RSS News Feed For Recently Posted Hints And Tips  RSS Feed
You can now get updates to the Recent Tips section by using RSS. The address is:

HintsAndTips.com/Rss.aspx

* Posting Tips *
To post a Tip, Recommendation or Tips Wanted, simply browse to the category you feel is a best fit for your post (click on the Recommention or Tips Wanted tab if fitting) and then click on "New Post" option.
(C) Copyright 1998-2010 All Rights Reserved