Solved

using code block with <%# instead of <%=

Posted on 2014-10-24
4
74 Views
Last Modified: 2014-10-28
Can anyone explain what the difference is between using a code block with  <%#  instead of  <%=   ?

When adding controls dynamically to a page, the later causes:

“The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).”
0
Comment
Question by:HLRosenberger
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Kyle Abrahams
ID: 40402541
<%= is a shortcut for response.write
<%# is used during databinding.

More info can be found here:
http://forums.asp.net/post/1828702.aspx
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 40402618
Thanks!  that was useful.

I'm using a third party WEB page generator tool.  It create stuff like this:

<%= SystemUtils.GenerateEnterKeyCaptureBeginTag(FindControlRecursively("CancelButton"))%>

The <%= prevents me from adding controls dynamically to a page.  Question:  Does changing <%= to <%# have any impact?  Can <%#  always be used instead of <%=?
0
 
LVL 39

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 40402653
Basically if the control you are trying to use is not in a databindable container you're going to run into issues.

Also you have to first databind the control before any data will display.

Example:
you put a datagrid on a webform.  The header shows up.  You databind the grid and the rows now show up.

that's using the <%#
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40409422
thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now