Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net <%$ ... %> syntax

Tags:

I'm trying to make the switch from Java to .NET.

I've noticed a number of ASP.NET pages have <%$ sometext %> in them. Can someone explain what this does in a couple of sentences, or point me to a reference on the syntax?

like image 510
Jay Avatar asked Oct 28 '11 19:10

Jay


1 Answers

It's expression builder syntax, and it's used commonly to access settings in the web.config. Here's an example using expression builder syntax to get a connection string:

ConnectionString="<%$ ConnectionStrings:sqlconnection %>" 

Here's a good article that explains all of the inline expressions:
http://support.microsoft.com/kb/976112

The expression builder is used to set values of control properties based on the information that is contained in an application's configuration or resource files. The following is the basic syntax of the expression builder: <%$ Expression Prefix: Expression Value %> The dollar sign ($) indicates to ASP.NET that the following expression is an expression builder. The expression prefix defines the kind of expression, such as AppSettings, ConnectionStrings, or Resources. Additionally, you can create and define your own expression builder. The expression value that follows the colon (:) is what ASP.NET will actually use as the value of a certain property.

like image 192
James Johnson Avatar answered Nov 16 '22 22:11

James Johnson