The Controls collection cannot be modified because the contr

Source: Internet
Author: User

Just now, Insus. NET has tried to change a piece of code, which is a small function that allows users to dynamically change the webpage background image. When Insus. NET executes the button Click event, it returns a title error.
The Code is as follows:




There was no problem with this code, but now I have added the #6 lines of code, which is a button. When the click event is executed, an exception occurs. The Click Event code is as follows:



How can this problem be solved?
Finally, I found a method on the Internet:
Http://leedumond.com/blog/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks/
About ):



As Insus. NET understands, replace "=" with "#" And Bind data to the Page_load event.



In the Page_load event:



OK.
However, Insus. NET wants to solve this problem using its own method.
Remove the style of the webpage head node:



Go to the Page. aspx. cs's Page_Load to remove the sentence: Page. Header. DataBind ();



And add a method protected override void OnInit (EventArgs e)



The Click event of the button has not changed:



# The difference between image a and Image B is that the image name is different. Refactoring:



Take a look at the dynamic change page background image:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.