Lỗi ‘The Controls collection cannot be modified because the control contains code blocks’ trong C# ASP.Net

Mới đi loanh quanh mấy ngày không đụng tới máy tính, bữa nay T2 đầu tuần việc dồn lại thành đống và phải giải quyết hơn phân nửa trong ngày nay nên không tìm hiểu dông dài nữa.

Nguyên nhân xuất hiện cái lỗi này thường là do có chèn tag <%   %> để viết code behind ở đâu đó trong trang aspx. Chỉ cần rà soát và thay đổi bằng cách đem hẳn vào code behind hoặc một số trường hợp xài trong mấy cái control như GridView thì chuyển sang dùng khai báo <%#  %> cũng có thể giải quyết được vấn đề.

Server Error in ‘/’ Application.


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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

 

 

Trả lời

Điền thông tin vào ô dưới đây hoặc nhấn vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất /  Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất /  Thay đổi )

Connecting to %s