我正在创建一个自定义 Web 控件,但是当我在 .cs 文件中引用它时,我在 .ascx 文件上的控件为空。我错过了什么吗?
.ASCX
<asp:Table runat="server" BorderWidth="0" BorderStyle="None">
<asp:TableRow VerticalAlign="Middle" BorderWidth="0">
<asp:TableCell HorizontalAlign="Center" BorderWidth="0" BorderStyle="None">
<asp:Button ID="button" runat="server" Text="Button" />
</asp:TableCell>
</asp:TableRow>
<asp:TableFooterRow BorderWidth="0" BorderStyle="None">
<asp:TableCell HorizontalAlign="Center" ID="caption" Font-Size="12pt" Height="80px" VerticalAlign="Top" BorderWidth="0" BorderStyle="None" BorderColor="Transparent" />
</asp:TableFooterRow>
</asp:Table>
.ASCX.CS
public void Process()
{
button.Text = "ok"; //it fails here because it's null;
}
测试.aspx
MyButton button = new MyButton();
button.Process();