Controls collection cannot be modified Archives : Binary Bits https://blog.binarybits.net/tag/controls-collection-cannot-be-modified/ Bits & Pieces - A blog by Kannan Balasubramanian Mon, 13 Feb 2012 12:24:45 +0000 en-GB hourly 1 https://wordpress.org/?v=6.5.2 The Controls collection cannot be modified because the control contains code blocks (i.e. ). https://blog.binarybits.net/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-i-e/ https://blog.binarybits.net/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-i-e/#respond Mon, 13 Feb 2012 12:24:45 +0000 https://blog.binarybits.net/?p=211 While I was writing an in-line code with javascript inside the master page I was constantly facing the following exception. The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>). Welcome, <script type=”text/javascript”>var loginName = “<%= SPContext.Current.Web.CurrentUser.Name %>”;document.write(loginName);</script> Found out that the javascript with c# code needs to be out of […]

The post The Controls collection cannot be modified because the control contains code blocks (i.e. ). appeared first on Binary Bits.

]]>
While I was writing an in-line code with javascript inside the master page I was constantly facing the following exception.

The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).

Welcome, <script type=”text/javascript”>var loginName = “<%= SPContext.Current.Web.CurrentUser.Name %>”;document.write(loginName);</script>

Found out that the javascript with c# code needs to be out of the tag which has runat=”server”. After checking the code I re-wrote the code into 2 pieces

<script type=”text/javascript”>var loginName = “<%= Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.Name %>”;</script>

The above code I moved out of the “<form runat=”server”…” code and the below code inside the required location.

<span>Welcome, <script type=”text/javascript”>document.write(loginName);</script></span>

Now the page is rendered properly.

 

The post The Controls collection cannot be modified because the control contains code blocks (i.e. ). appeared first on Binary Bits.

]]>
https://blog.binarybits.net/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks-i-e/feed/ 0