ASP.NET 用户控件绑定
我在 asp.net 中创建了一个具有自定义属性的用户控件,如下所示。在使用此用户控件的 aspx 页面中,我有如下内容。用户控件位于 FormView 的 EditItemTemplate 中,
<uc1:MyControl ID="c1" runat="server" CountryCode='<%# this.DropDownCountry.SelectedValue %>' Value1='<%# Bind("Value1Col") %>' />
我尝试在用户控件的 Page_Load
方法中使用 CountryCode
,但该值尚未填充。
我的问题是在控件生命周期的哪个阶段填充有界值?我尝试像下面这样直接赋值,它确实在 Page_Load
方法中获取了它的值。
<uc1:MyControl ID="c1" runat="server" CountryCode="CA" Value1='<%# Bind("Value1Col") %>' />
谢谢,
uc1:MyControl 具有以下属性:
[Browsable(true)]
[Bindable(true, BindingDirection.TwoWay)]
[DefaultValue(0)]
[PersistenceMode(PersistenceMode.Attribute)]
public string CountryCode
{
get { return _countryCode; }
set { _countryCode = value; }
}
i created a user control with a custom property in the asp.net like the following. In the aspx page that uses this user control i have something like the following. The user control is in a FormView's EditItemTemplate
<uc1:MyControl ID="c1" runat="server" CountryCode='<%# this.DropDownCountry.SelectedValue %>' Value1='<%# Bind("Value1Col") %>' />
I am trying to use the CountryCode
in the Page_Load
method of the user control, but the value has not be populated.
My question is at which stage in the control's life cycle does the bounded value gets populated? I tried assigning value directly like the following and it does get its value at the Page_Load
method.
<uc1:MyControl ID="c1" runat="server" CountryCode="CA" Value1='<%# Bind("Value1Col") %>' />
thanks,
the uc1:MyControl has the following property:
[Browsable(true)]
[Bindable(true, BindingDirection.TwoWay)]
[DefaultValue(0)]
[PersistenceMode(PersistenceMode.Attribute)]
public string CountryCode
{
get { return _countryCode; }
set { _countryCode = value; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用的是数据绑定语法,因此需要在控件上调用 DataBind 方法 - 您可以将其添加到 aspx 页面的 Page_Load 方法中,如下所示:
Since you're using databinding syntax you need to call DataBind method on your control - you can add this to the Page_Load method of the aspx page like so: