Solved

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

Posted on 2014-10-24
4
80 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 40

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 40

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

696 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