programmatically change a user controls properties

luciencoffey30

New Member
How do i programmatically change a user controls properties in c#?<BR><BR>I've made a really simple user control (.ascx) which just displays a couple of news from a certain category. so i added<BR>a public integer to the control so i could specify which category<BR>i should take news from. This works:<BR><MyUC:MyControl runat=Server CategoryID="1"></MyUC:MyControl><BR><BR>but i want it to change it programmatically, and i thought that would look something like this (where CategoryID is a integer set to 1 in the Page_Load function):<BR><MyUC:MyControl runat=server CategoryID="<%# CategoryID %>"></myUC:MyControl><BR><BR>it doesn't complain about this, but the CategoryID property is never set :(<BR><BR>Any ideas?<script language="vb" runat="server"><BR><BR> sub Page_Load(sender as object, e as EventArgs)<BR><BR> yourControl.CategoryID = 1<BR><BR> end sub<BR><BR></script><BR><BR><MyUC:MyControl runat=Server id="yourControl" /><BR><BR><BR>(As you can see, I left off the @Register directive... this will need to be added...)
 
Top