[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!