ASP.NET Server tags cannot contain <% ... %> constructs

Tags: asp.net c#

We've all seen the Server Tags cannot contain <% ... %> constructs which comes from trying to use server side <% .. %> inside a server side control:


<asp:TextBox runat="server" Text="<%= ConfigurationManager.AppSettings["Title"] %>" />


You have a few ways around this, the easiest and most common way is to assign the properties server side:


this.textBox1.Text = ConfigurationManager.AppSettings["Title"];


But I like being able to do as much of my property setting in markup as possible so if I ever need to change the property it doesn't require a complete re-build/re-deploy.


The more elegant/fun solution would be to use an ExpressionBudiler, you've most likely used this class already if you've ever worked with a a multilingual website, to have controls pull globalized text from your resx resources you do the following:


<asp:Label runat="server" Text="<%$ Resources:Text, ParticipantHeader %>" />


This is using a ResourceExpressionBuilder, there is also an AppSettingsExpressionBuilder and a ConnectionStringsExpressBuilder built into the .NET framework that you can use. If these don't do what you want you can always build your own, you can see an example of a custom ExpressionBuilder at the MSDN Documentation.

Comments
2010-03-05 20:06:51 - Cedric Matteucci

Fantastic post! This could aid lots of people find out about this matter. Do you want to incorporate video clips together with these? It could undoubtedly help out. Your reason was spot on and owing to you; I probably won't have to describe everything to my pals. I can simply direct them here

2010-03-06 11:57:58 - Peter

Great Post. I would love to read more in future. keep up the good work. Yearly hosting http://www.intelweb.biz

2010-03-07 06:19:40 - reverse phone lookup

Hello everybody. I have been searching the Internet for fun when I found your website. Terrific post. Thanks a ton for sharing your knowledge! It is encourging to know that some people still put in an effort into managing their websites. I'll be sure to check back again real soon.

2010-03-07 23:14:47 - moon in my room

Thanks for taking this opportunity to talk about this, I feel strongly about it and I benefit from learning about this subject. If possible, as you gain data, please update this blog with new information. I have found it extremely useful.

2010-03-08 05:20:47 - Watch Free Movies

Great concepts on this webiste. It's rare these days to get sites with info you're trying to find. I am glad I discovered this website. I will actually bookmark it or perhaps subscribe to your rss feeds just to be updated on your new posts. Sustain the good work and I'm sure another folks looking for valued information will definitely stop by and benefit from your website for resources.

2010-03-08 11:22:48 - Hypno

Can you email me back, please. Thank you.

2010-03-08 15:38:11 - zynga

i am quite often bumping throughout the online world nearly all of the time so I tend to read an awful lot, which isnt usually a good matter as many of the internet sites I view are made up of unnecessary waste copied from many other web pages a trillion times, on the other hand I have to compliment you because this blog is in actual fact readable and has a bit of genuine content, therefore cheers for breaking the trend of just copying other individual's websites, in case you ever want to take up a few hands of facebook poker together just gimme a shout - you have my email address :)

2010-03-09 01:56:34 - Leoma Lebrane

very nice. great post

2010-03-09 06:29:16 - Optimizacija spletnih strani

Thanks for this useful blog. i found your blog on google and find it is very useful.

2010-03-09 11:38:29 - Vrata

Impressive blog! Its not often that I comment but I felt you deserve it

2010-03-10 01:30:37 - PVC vrata

I enjoy reading your site.

2010-03-10 05:51:32 - WoW Leveling Guide

I had to refresh the page 2 times to view this page for some reason, however, the information here was worth the wait.

2010-03-10 17:28:19 - Kendall Feister

Pretty insightful post. Never thought that it was this simple after all. I had spent a good deal of my time looking for someone to explain this subject clearly and you’re the only one that ever did that. Kudos to you! Keep it up

2010-03-10 19:55:18 - reverse white pages

It is refreshing post The particular information I discovered beneficial. We have bookmarked it and will come by for a second time subsequently. Regards.

2010-03-10 22:36:23 - chi flat iron

Great blog post! I have bookmark this and subscribed to your RSs keep me update with your latest.

2010-03-15 07:54:04 - Ora Rigoni

Hey - great website, just looking for some websites about Sad Rock Songs because I have made a fresh site about it and need a little bit more input what to put online and what not. Maybe you can help me ?! I don't want to publish only Song Texts and such stuff. Thanks

2010-03-15 13:12:54 - bicycle repair in us

Now, my best recommendation is for you to start off with blogger if you are new to the blogging arena.

2010-03-15 22:41:04 - Online Home Business

I hold listening towards the news converse about having no cost on the internet grant applications so I have been

2010-03-16 05:12:56 - SweetSusiNRW

Wetteinsatz 1/3

2010-03-16 06:34:55 - Ima Polee

thanks for posting this

2010-03-17 17:13:38 - play online games

Incredible! Many thanks! I always wished to write in my site something similar to that. Am i allowed to quote section of your post to my weblog?

2010-03-17 17:35:21 - order viagra now online

The availability of Viagra pills on the internet means that the online pharmacies are now being patronised by most people who want to buy Viagra cheap. Not only does the internet offer a more affordable option than the local pharmacies for Viagra pills, they are also more convenient in terms of the confidentiality they offer customers.

2010-03-17 21:26:42 - watch the pacific episode 1

Ola... Hello there. Sorry but my english is not nice.anyway...i just desire to tell that i like this post a lot.Thanxxxx