Solved

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

Posted on 2014-10-24
4
81 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

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'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

691 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