tags:

views:

153

answers:

1

Is it possible to do things in a PHPish way in ASP.Net? I've seen <%= %> but I've tried it and couldn't get it to work.

The PHPish equivalent of what I want to do is

<script src="<?php echo ResolveUrl("jquery/js/jquery.js"); ?>"></script>
+2  A: 

Yes, it's quite possible. You should familiarize yourself with all the variations of the (so called) alligator tags though.

Put code in between <% %> blocks. The <%= %> variant is a shortcut for Response.Write, and is used as a shortcut for directly outputting a variable to the page.

The following should work, as long as ResolveUrl is returning a string. Notice there is no ";" to end the line though.

<script src="<%= ResolveUrl("jquery/js/jquery.js") %>"></script>
womp
Just to make a note, I later changed my code to use `<%# %>` instead because of this issue http://stackoverflow.com/questions/778952/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blo
Earlz
Don't forget <%: %> in asp.net 4.0 for HtmlEncoding
Aren