The Controls Collection Cannot Be Modified Because The Control Contains Code Blocks
Mar 27, 2011
i saw few of solutions for this exception (like putting it in place holder, or replace the <% to <# ...etc) , but i don't get the idea about it, i mean what is the controls collection? and why it can't be modified if the added control contains code blocks?
I recently put some code <% %> code blocks in my Master Page. Note I've read of the "fix" for either moving things out of <head> or using <%# %> but neither of them work well for my application.
Now the weird thing is that I only get this error on one page of mine. All the other pages seem to work fine, so what actually causes this error? There is nothing I can think of that is unique about this page. It uses the script manager as does other working pages and there is just nothing extraordinary about this page. It does have quite a few custom controls on it, so hunting down what is different in this page is more difficult than usual.
So what actually causes the Controls collection cannot be modified because the control contains code blocks exception?
I am getting http exception in of the method of class file (search.aspx.vb) like "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)",
I have tried placing Java script function in the body of Master page from header, whereas I just removed the Java script tag and its contents in search.aspx (as of its not required now). Still getting exception.
I also know that if we have something like this <%= in Java script function we need to replace with <%#. But I don’t have this kind of code in any function.
I want use meta tag in my page that read keyword from database
I set this code in my product.aspx page
protected void Page_Load(object sender, EventArgs e) { SqlCommand _cmd = new SqlCommand("select Keyword1 + ',' + Keyword2 + ',' +Keyword3 from House_info where BehCode=1115", _cn); _cn.Open(); SqlDataReader _dr = _cmd.ExecuteReader(); while (_dr.Read())
[Code] ....
It worked correctly and show my keywords from database and show it in my product.aspx metatag
I have two other page
index.aspx and store.aspx in index.aspx i have 1button and 1 TextBox when user type their BEHCODE(columns name in users table) in TextBox it go to store.aspx page and show that users information on store.aspx
Now i want set meta tag in store.aspx page and i want fill store.aspx meta tag from my users table in data base
The code on one of my aspx pages is giving me this error:
I'm getting this on the code behind for export to excel on one of my pages.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).It is referring to this line Me.GridView1.Parent.Controls.Add(frm)
I have this code in the aspx page. I am using two gridviews. I need to have this on the page any way I can fix the code so I can use that export to excel you created?
and it was working well even After I upgraded my wevbsite to .net version 4 but when I started a new website from scratch in vs2010 using .net4 when I use ajax toolkit in this new site it is registered as folowing
and when I run the page I get the error The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>) I don't Know what is the reason for this. I noticed another thing. in my old website I was using thckbox script by using the files common.js, jquery-1.3.2.js,jquery.thickbox.js and puting them in a Javascript folder ad then registering them in Script manager as following
this was working well also but in my new site the jquery file version was jquery-1.4.1.js but also I added the old version f the javascripts files in the built in Scripts folder that is created by default b the new site and followed the same way in registering them in the script managerchange the JavaScript folder to the built in folder Scripts
but this doesn't work also in the new site I think that there is something diffirent in the 2 case which leads to this change in performance I wish your support and advice about how to solve this matter
I'm receiving this error on a page that previously worked fine, in fact the only change I've made to the page recently was to add another asp:TextBox and asp:RequiredFieldValidator control.
The page already had numerous ASP.NET controls on it, so I cannot see why these extra controls would make a difference, anyway I shall post the code below and hopefully you can see what the error is:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MeetingGenerator.ascx.cs" Inherits="usercontrols_MeetingGenerator" %>[code]......
I am getting this error after I add <head runat="server"> The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
i always get this error when ever i use DropdownExtender,Additional information:The Controls collection cannot be modified because the control contains code blocks i.e. <% ... %>).this is my ASPX Code
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
I am using it in Gridview's EditTemplate Field to show color with ajax 3.5
I got 2 listboxes in a window form, one on left and one on right. The 1st listbox have some items while the 2nd listbox is empty. Also there are 2 buttons between the 2 listboxes which used to move item from/to the 1st and 2nd listbox.My problem here is that after I bind the data to the 1st listbox (from a dataTable, using DisplayMember and ValueMember) , and I try to move 1 of the item from this 1st listbox to the 2nd listbox and I want that the selected item is also removed from the 1st listbox by:
But the selected item is not removed from the 1st listbox.Also on deselect button when i move item from 2nd listbox to 1st listbox,it displays error message "Items collection cannot be modified when the DataSource property is set."
I am using a grid, with udpate panel, ajax controls etc.So in my code behind everytime the hit my grid page I am clearing the previous session value stored.I do this:
[Code]....
But sometimes when i navigate to other pages and come back to this page it errors out saying:
" Collection was modified after the enumerator was instantiated."
Just before (or during) rendering page I would like to append a piece of code (java script). However when I try to add new LiteralControl via Page.Controls property I get an error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
I'm storing a dataset in an ASP.Net WebApplication-Cache. Every user in this intranet-app uses the same instance. On insert/update/delete-actions the database will be updated and the dataset is modified accordingly.
But rarely I get an exception that indicates that I've missed something. I assume that it must have something to do with thread safety.
Collection was modified; enumeration operation might not execute
In lines where i access a DataTable in the Dataset, for example:
Dim view As New DataView(dsERP.ERP_Charge, filter, sort, _ Data.DataViewRowState.CurrentRows)
It was apparently changed by another thread while the view enumerates the datatable.
What is the best way to make this thread safe?
Edit: as you've mentioned i need to lock the objects on add/edit/delete operations. MSDN* says that a DataSet is thread-safe for multiple users. What does this mean, are the DataTables in the Dataset also thread-safe? And how to lock a single datatable on write-operations and not the whole dataset?
*ADO.NET - Multithreaded Programming ADO.NET is optimized for performance, throughput, and scalability. As a result, the ADO.NET objects do not lock resources and must only be used on a single thread. The one exception is the DataSet, which is thread-safe for multiple readers. However, you need lock the DataSet during writes.
This is the property that returns the dataset:
Public ReadOnly Property dsERP() As ERPModel.dsERP Get If Cache("DS_ERP") Is Nothing Then Cache("DS_ERP") = New ERPModel.dsERP FillDataSet() End If Return DirectCast(Cache("DS_ERP"), ERPModel.dsERP) End Get End Property
i've modified the insert/update and delete operations in the following way(dsRma is a dataset):
Dim success As Boolean SyncLock dsRMA.RMA success = insert() End SyncLock
First, does it work now if another thread tries to enumerate the RMA-Table? Second, is it sufficient to lock the datarow that gets updated instead of locking the whole datatable(see below)?
Dim thisRMA As ERPModel.dsRMA.RMARow = dsRMA.RMA.FindByIdRMA(Me.IdRma) Dim success As Boolean SyncLock thisRMA success = update(thisRMA) End SyncLock
I have an ASCX control which is a special dropdownlist. I add that control dynamically to the page and fill it with data. This control has a postback that will change the contents of a second dynamically created standard dropdownlist.
When I change the selection on the first dropdown, the indexchanged fires and I get new data and attempt to place it in the second dropdownlist's items collection, by first clearing it then filling it with new data.
This works fine the first time a change the selection, but when I select a second time the following error is thrown:
The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.
I'm not adding or removing new controls in the fired event, only changing data. And again, it works the first time, but doesn't subsequent times.
If I disable stateview on the child control, then the control just doesn't get updated with data at all.
public int deleteProduct(int ProductID, int rowid) { // Create the Database object, using the default database service. The // default database service is determined through configuration. Database db = DatabaseFactory.CreateDatabase(); DataSet productsDataSet = new DataSet();
[Code] ....
The above code am using but throwing below error how to resolve
"Update requires a valid UpdateCommand when passed DataRow collection with modified rows."