且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将值从页面传递到用户控件

更新时间:2023-12-06 08:43:16

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

<uc1:myUserControl ID="uc1" runat="server" myIntProperty="5" />