The .NET Knowledge Sharing Thread

Status
Not open for further replies.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

This error occurs when using javascript to access control with e.g. $find("<%= Control.ClientID %>"), together with RadAjaxPanel, in a Master/Client page setup in asp.net


One solution is to put the script in a body tag,
http://www.telerik.com/community/fo...e-control-contains-code-blocks-i-e-lt-gt.aspx

BUT
You cant use body in a Contentplaceholder
http://www.dotnetspider.com/forum/256403-How-use-body-body-tags.aspx



All the solutions refer to only being able to fix the problem by starting the code block with <%# instead of <%=
http://leedumond.com/blog/the-contr...ied-because-the-control-contains-code-blocks/
but this does not help if you have $find("<%= Control.ClientID %>") , which refers to a control.
Also, you can try : in master page load event : Page.Header.DataBind()


ive also tried to rather user
var oConatctName = document.getElementById('EtxtContactName').value;
than
var oConatctName = document.getElementById('<%#EtxtContactName.ClientID%>').value;
but it does not work


turns out i just had to put the javascript into a RadCodeBlock
http://www.telerik.com/help/aspnet-ajax/ajxradscriptblockradcodeblock.html
 
Last edited:
when moving crystal reports from e.g. dev environment to deployment environment,
you need to update the datasource location

when you create a new connection string, dont ever use SQL NATIVE CLIENT.
it'll bomb you out like you wont believe

Use MICROSOFT OLE DB Provider for SQL SERVER
 
note to self
when migrating a normal aspx page to a content page of a master page,
make sure to remove the MOTHEREFFING scriptmanager from the content page!!
its a know fact you cant have a scriptmanager on the content and master page, but theres no build error and its not always easy to see and remember
 
note to self
you cant get checkbox text property from javascript,
because there is no text attribute,
<input id="ctl00_ContentPlaceHolder1_CheckBoxList1_0" type="checkbox" name="ctl00$ContentPlaceHolder1$CheckBoxList1$0" onclick="MyFunction(MyValue);" />
<label for="ctl00_ContentPlaceHolder1_CheckBoxList1_0">CustomerName</label>
workaround i used, pass the value in the onclick event, strip it from there
 
A neater approach for when an event handler only has a few lines:

myBtn.Clicked += (s,e)=>
{
//Do stuff here.
//To get the sender either cast the s to whatever type it is like this:
Button btn = s as Button;
btn.Text = "hello";
//Or use the original reference because we are still in the same context:
myBtn.Text = "hello";
};


Note that you must never use the "myBtn" reference when creating objects and their handlers in a loop because no matter which object fires the event the "myBtn" reference will point to the last one. Use the sender.
 
In Silverlight there's a bug (well, probably an undocumented feature :P) where re-binding a control will sometimes throw a very unspecific error. First set the ItemSource to null then bind to fix it.
 
A neater approach for when an event handler only has a few lines:

myBtn.Clicked += (s,e)=>
{
//Do stuff here.
//To get the sender either cast the s to whatever type it is like this:
Button btn = s as Button;
btn.Text = "hello";
//Or use the original reference because we are still in the same context:
myBtn.Text = "hello";
};


Note that you must never use the "myBtn" reference when creating objects and their handlers in a loop because no matter which object fires the event the "myBtn" reference will point to the last one. Use the sender.

**** like that makes me cringe.

if you going to cast the button to a button just var btn = s as Button; or you mind as well just do ((Button)btn).Text = "Hello"; Furthermore i would rather use Rx for the event subscribing.
 
WCF windows service installation: you have to run your command prompt as admin.
Shortest way is to create your Visual Studio Command Prompt (2010) a desktop shortcut and run as administrator

Then cmd-> installutil whatever.exe
or link or link 2
 
Last edited:
note to self
visual studio: project cant compile but shows no errors : there could be a 2 pages with different aspx names, but with the same "Partial Class MyFile" in the solution.
this will also have the effect that the moment you try to access any "new" control on that page, you will not be able to compile and if youre lucky you will get the message: labelXYZ is not a member of MyFile, even though you see labelXYZ - it means that the first MyFile does not have a labelXYZ and the project is trying to use the first instance of MyFile.
 
Status
Not open for further replies.
Top
Sign up to the MyBroadband newsletter
X