. Net custom control display and passing Parameters

Source: Internet
Author: User

[Original] transmits parameters and values to the custom control. ascx file to make your custom control more available

After searching for a long time on the Internet, I finally got no results. Finally, I was inspired by the Code sent by a person.
Declare the control properties in the control. ascx. cs.
Private int _ ClassID = 0;
Public int ClassID
{
Get {return _ ClassID ;}
Set {_ ClassID = value ;}
}
On the aspx page, <uc1: tc id = "TID" runat = "server" ClassID = "100"/> to pass parameter values to the control that wants to pass parameters,

On the aspx page
<Uc1: UC_UserClass id = "UC_UserClass1" runat = "server"> </uc1: UC_UserClass>

Background. aspx. cs code
Protected UC_UserClass UC_UserClass1;
This sentence is important. By default, it will not be added during addition,
It is easy to use in VS2005, but it is troublesome in VS2003. You must manually add the variable name, and the variable name must be the same as on the previous page.
I used VS2005 for development without any problems. Now I am very depressed when I try VS2003 again.

It's hard to get it done. You can give it a try.
If (! Page. IsPostBack)
{
UC_UserClass1.ClassID = 123456789; // the value you want to pass
}
// You can pass the value to him.
// You can also obtain controls on custom controls.
DropDownList drp1 = UC_UserClass1.FindControl ("drp1") as DropDownList;
Of course, besides passing values, you can also call the public method and public Function in it.

It's easy to solve the problem!

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.