Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now