ASP. NET

Source: Internet
Author: User

If you use a user control on the aspx page, you may need to obtain a reference to the control object to perform some operations. The FindControl method is generally called to obtain control references. However, this method returns the Object type and requires forced type conversion. So the question is: how to obtain the user control type?

In my first practice, I used the type automatically generated in the ASP namespace. For example, if I create a user control named policyforcelabel. ascx, A controls_policyforcelabel_ascx type is automatically generated in the ASP namespace. Therefore, the statements used to obtain user control references are as follows:

ASP. controls_policyforcelabel_ascx policyforcelabel = (ASP. controls_policyforcelabel_ascx) this. FindControl ("VicctoryForceLabel ");

This is completely normal during the test. However, once a website is published, an error message always appears:

The namespace "ASP" does not contain a type or namespace name "controls_policyforcelabel_ascx" (is the Assembly reference missing ?)

This error is confusing. I searched the internet and found that the error type was used. In fact, the user control type is not automatically generated in the ASP namespace, but in the control code file. For the preceding user control, this type is the controls_policyforcelabel class defined in the policyforcelabel. ascx. cs file. After the type is replaced, the release is successful.

As to the usage of automatically generated types in ASP namespaces and why are everything normal during the test, you need to learn more about answering these questions.

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.