Pass values from page to user control

前端 未结 5 1594
别那么骄傲
别那么骄傲 2021-02-14 07:21

I am storing name and last name in two labels in main page. I also have those values in a class (class doesnt do much but i am using them for future expansion). I have a user co

5条回答
  •  你的背包
    2021-02-14 08:14

    Create a property on your user control with the datatype of the data you want to pass to it, and populate it in your page on creation of the control.

    public class myUserControl : Control
        {
          ...
          public int myIntProperty {get; set;}
          ...
        }
    

    Later this in the code behind you can assign the value like

    myUserControl cntrl = new myUserControl();
        cntrl.myIntProperty = 5;
    

    Instead of this you can pass the value through Markup also like

    
    

提交回复
热议问题