使用ascx目的就是为了提高某部分功能的重复利用,我简单通过源代码说一下对它的参数的输入和数出。
我们以省市区三级连动为例子。
vs2005下ascx页面的代码:
<table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <asp:DropDownList id="ddlProvince" runat="server" Width="100px" AutoPostBack="True" OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged"> </asp:DropDownList> <asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline"> <ContentTemplate> <asp:DropDownList id="ddlCity" runat="server" Width="100px" AutoPostBack="True" OnSelectedIndexChanged="ddlCity_SelectedIndexChanged"> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlProvince" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline"> <ContentTemplate> <asp:DropDownList id="ddlDistrict" runat="server" Width="100px"> </asp:DropDownList> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlCity" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> </td> </tr> </table>
ascx后台代码:
public partial class UserControl_ProvinceAndCityAndDistrict : System.Web.UI.UserControl { ///// <summary> ///// 选择区域的iD ///// </summary> protected string _districtValue; [Bindable(true), Category("Appearance"), DefaultValue("")] public string districtValue { get { return _districtValue; } set { _districtValue = value; } } protected string _cityValue; [Bindable(true), Category("Appearance"), DefaultValue("")] public string cityValue { get { return _cityValue; } set { _cityValue = value; } } protected string _provinceValue; [Bindable(true), Category("Appearance"), DefaultValue("")] public string provinceValue { get { return _provinceValue; } set { _provinceValue = value; } } private void setValue() { if (_provinceValue != string.Empty) { this.ddlProvince.SelectedItem.Text = _provinceValue; } if (_cityValue != string.Empty) { this.ddlCity.Selecte |