0

It gives the following error

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

My code is

  __doPostBack('<%= btnExitChatRoom.ClientID %>', '');
Mangal Pandey
  • 109
  • 13

2 Answers2

0

The error does not come from that Javascript code per se. The code behind your page is trying to add or remove controls from a container that includes code blocks (<%= btnExitChatRoom.ClientID %> in your case), and ASP.NET cannot do that.

You can work around this problem by using a data binding expression:

__doPostBack('<%# btnExitChatRoom.ClientID %>', '');

Then explicitly calling the DataBind() method of the container from your code-behind.

Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
0

If you don't want to databind then take this code out of the header and put it just before the element closes

Ben
  • 1,913
  • 15
  • 16