asp.net user control binding
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(Pers开发者_JS百科istenceMode.Attribute)]
public string CountryCode
{
get { return _countryCode; }
set { _countryCode = value; }
}
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:
protected void Page_Load(object sender, EventArgs e)
{
c1.DataBind();
}
精彩评论