是选择国家,地区,省份,市,县的.
控件有个方法
this.City_Select_All_In_One1.setLocationCode(国家,地区,省份,市,县);
参数默认为空值
当有国家代码的时候,(地区,省份,市,县)三个下拉框隐藏...
当有国家,地区,省份的时候,显示这三个DropDownList.其它两个市,县Panel是隐藏的!
这个控件在测试页面 用按钮点击事件,调用setLocationCode方法,控件会显示出我们需要的面板
(国家,地区,省份,市,县)Panel都会自动展开.....一切正常...
protected void btn_submit_Click(object sender, EventArgs e)
this.City_Select_All_In_One1.setLocationCode(国家,地区,省份,市,县);
但是我在 测试页面的页面加载初始化时候调用,控件Panel面板就没有反应....不会响应setLocationCode方法....
protected void Page_Load(object sender, EventArgs e)中
this.City_Select_All_In_One1.setLocationCode(国家,地区,省份,市,县);
没有一点反应..
这个是不是和用户控件的生命周期有关系?
Page_Load中控件没有初始化成功,无法调用控件事件setLocationCode方法???
实在没有方法.no clue...
解决后另外开贴加分....200分
11 个解决方案
#1
部分的控件代码...
public partial class UserControls_City_Select_All_In_One : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDDL(DDLzhou_code, new NewMd.Core.WorldCityList().zhouByDisp(), "citypostcode", "cityname");
this.DDLzhou_code.SelectedIndex = 5;//默认为亚洲
this.SetDDlDefaultText(DDLzhou_code, "亚洲");
//验证控件
//this.validate_zhou.Enabled = true;
//this.validate_guojia.Enabled = false;
//this.validate_diqu.Enabled = false;
//this.validate_sheng.Enabled = false;
//this.validate_dijishi.Enabled = false;
//this.validate_xianjishi.Enabled = false;
//选择国家面板=中国
this.DDLzhou_code_SelectedIndexChanged(null, null);
this.Chkzhou_code.Checked = true;
this.Chkzhou_code_CheckedChanged(null, null);
//显示省份面板=未选择
this.DDLguojia_code_SelectedIndexChanged(null, null);
//this.Chkguojia_code.Checked = true;
//this.Chkguojia_code_CheckedChanged(null, null);
}
}
private void BindDDL(DropDownList ddl, DataSet dt, string strValueField, string strTextField)
{
ddl.DataSource = dt;
ddl.DataValueField = strValueField;
ddl.DataTextField = strTextField;
ddl.DataBind();
}
//选择国家代码
protected void DDLguojia_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLdiqu_code.Items.Clear();
this.DDLdiqu_code.Items.Add(new ListItem("请选择地区", "0"));
BindDDL(DDLdiqu_code, new NewMd.Core.WorldCityList().diqu(DDLguojia_code.SelectedValue), "citypostcode", "cityname");
DDLdiqu_code_SelectedIndexChanged(null, null);
}
//选择地区代码.联动
protected void DDLdiqu_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLsheng_code.Items.Clear();
this.DDLsheng_code.Items.Add(new ListItem("请选择省份", "0"));
BindDDL(DDLsheng_code, new NewMd.Core.WorldCityList().sheng(DDLdiqu_code.SelectedValue), "citypostcode", "cityname");
DDLsheng_code_SelectedIndexChanged(null, null);
}
//选择省份代码.联动
protected void DDLsheng_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLdijishi_code.Items.Clear();
this.DDLdijishi_code.Items.Add(new ListItem("请选择地级市", "0"));
BindDDL(DDLdijishi_code, new NewMd.Core.WorldCityList().dijishi(DDLsheng_code.SelectedValue), "citypostcode", "cityname");
DDLdijishi_code_SelectedIndexChanged(null, null);
}
//选择地级市.联动
protected void DDLdijishi_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLxianjishi_code.Items.Clear();
this.DDLxianjishi_code.Items.Add(new ListItem("请选择县级市", "0"));
BindDDL(DDLxianjishi_code, new NewMd.Core.WorldCityList().xianjishi(DDLdijishi_code.SelectedValue), "citypostcode", "cityname");
}
private DropDownList GetSelectCity()
{
DropDownList Retval = DDLzhou_code;
if (Panel6.Visible)
{
return DDLxianjishi_code;
}
if (Panel5.Visible)
{
return DDLdijishi_code;
}
if (Panel4.Visible)
{
return DDLsheng_code;
}
if (Panel3.Visible)
{
return DDLdiqu_code;
}
if (Panel2.Visible)
{
return DDLguojia_code;
}
if (Panel1.Visible)
{
return DDLzhou_code;
}
return Retval;
}
#endregion
//获取城市代码
public NewMd.Model.City_CitySelect_all GetCity()
{
return 选定的城市代码;
}
/// <summary>
/// 提供数据回显的代码
/// </summary>
/// <param name="code">输入城市代码</param>
/// <returns>返回设定是否成功,UI是否回显</returns>
public bool setLocationCode(string code)
{
//安全检查位数
if (code.Length != 9)
{
return false;
}
if (code.Substring(1, 8) != "00000000")
{
this.Chkzhou_code.Checked = true;
this.Chkzhou_code_CheckedChanged(null, null);
}
if (code.Substring(3, 6) != "000000")
{
this.Chkguojia_code.Checked = true;
this.Chkguojia_code_CheckedChanged(null, null);
}
if (code.Substring(4, 5) != "00000")
{
this.Chkdiqu_code.Checked = true;
this.Chkdiqu_code_CheckedChanged(null, null);
}
if (code.Substring(5, 4) != "0000")
{
this.Chksheng_code.Checked = true;
this.Chksheng_code_CheckedChanged(null, null);
}
if (code.Substring(7, 2) != "00")
{
this.Chkdijishi_code.Checked = true;
this.Chkdijishi_code_CheckedChanged(null, null);
}
//绑定洲的代码...1
BindDDL(DDLzhou_code, new NewMd.Core.WorldCityList().zhouByDisp(), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLzhou_code, code.Substring(0, 1) + "00000000");
DDLzhou_code_SelectedIndexChanged(null, null);
//国家2
BindDDL(DDLguojia_code, new NewMd.Core.WorldCityList().guojiaBydisp(code), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLguojia_code, code.Substring(0, 3) + "000000");
DDLguojia_code_SelectedIndexChanged(null, null);
//地区4
BindDDL(DDLdiqu_code, new NewMd.Core.WorldCityList().diqu(code), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLdiqu_code, code.Substring(0, 4) + "00000");
DDLdiqu_code_SelectedIndexChanged(null, null);
//省份5
BindDDL(DDLsheng_code, new NewMd.Core.WorldCityList().sheng(DDLdiqu_code.SelectedValue), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLsheng_code, code.Substring(0, 5) + "0000");
DDLsheng_code_SelectedIndexChanged(null, null);
//地级市7
BindDDL(DDLdijishi_code, new NewMd.Core.WorldCityList().dijishi(DDLsheng_code.SelectedValue), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLdijishi_code, code.Substring(0, 7) + "00");
DDLdijishi_code_SelectedIndexChanged(null, null);
//县级市
BindDDL(DDLxianjishi_code, new NewMd.Core.WorldCityList().xianjishi(DDLdijishi_code.SelectedValue), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLxianjishi_code, code);
return true;
}
}
#2
用户控件是否动态加载
if(!IsPostback)
{
//调用this.City_Select_All_In_One1.setLocationCode方法,
参数默认为空值,应该先设置DropDownList国家,地区,省份,再显示Panel
使用ajax通过DropDownList级联选择很简单
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</div>
if(!IsPostback)
{
//调用this.City_Select_All_In_One1.setLocationCode方法,
参数默认为空值,应该先设置DropDownList国家,地区,省份,再显示Panel
使用ajax通过DropDownList级联选择很简单
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</div>
#3
我的问题是,为何在 测试页面的页面加载初始化时候调用,控件Panel面板就没有反应....不会响应setLocationCode方法....
页面的 Page_Load
s etLocationCode方法用[color=#0000FF]按钮点击事件调用是好的啊[/color]
#4
在调用控件的页面调用setLocationCode(string code)方法
设置下拉框值
设置下拉框值
#5
http://www.cnblogs.com/oletan/archive/2008/11/04/1326587.html
终于解决了问题,爷爷的...生命周期问题...
#region 调用方法事件...初始化控件...
protected override void OnSaveStateComplete(EventArgs e)
{
base.OnSaveStateComplete(e);
this.Web_Site_Select.setSiteCode("Wa", "Wa-80", "Wa-80803");
this.City_Select_All_In_One1.setLocationCode("Ycn330723");
}
#endregion
送分了..................
终于解决了问题,爷爷的...生命周期问题...
#region 调用方法事件...初始化控件...
protected override void OnSaveStateComplete(EventArgs e)
{
base.OnSaveStateComplete(e);
this.Web_Site_Select.setSiteCode("Wa", "Wa-80", "Wa-80803");
this.City_Select_All_In_One1.setLocationCode("Ycn330723");
}
#endregion
送分了..................
#6
你可能没有好好看问题,控件功能已经实现了!
就是调用方法的时候响应问题而已...
#7
执行顺序
控件的Init事件
控件所在页面的Init事件
控件所在页面的Load事件
控件的Load事件
控件所在页面的PreRender事件
控件的PreRender事件
控件的Init事件
控件所在页面的Init事件
控件所在页面的Load事件
控件的Load事件
控件所在页面的PreRender事件
控件的PreRender事件
#8
谢谢哦...有qq吗?
#9
#region SaveStateComplete 第九步
protected override void OnSaveStateComplete(EventArgs e)
我用这个方法,却无法保存控件的状态???
protected override void OnSaveStateComplete(EventArgs e)
我用这个方法,却无法保存控件的状态???
#10
现在好了,,,,,
控件属性
貌似无法存值...会丢失状态...(调用属性之前,已经set这个属性的值了...)
只有用方法才能返回真正的值
public string get*Code()
{
return this.DropDownList.SelectedValue;
}
控件属性
public string *Code
{
get { return _*_code; }
set { this._*_code = value; }
}
貌似无法存值...会丢失状态...(调用属性之前,已经set这个属性的值了...)
只有用方法才能返回真正的值
public string get*Code()
{
return this.DropDownList.SelectedValue;
}
#11
.......
#1
部分的控件代码...
public partial class UserControls_City_Select_All_In_One : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDDL(DDLzhou_code, new NewMd.Core.WorldCityList().zhouByDisp(), "citypostcode", "cityname");
this.DDLzhou_code.SelectedIndex = 5;//默认为亚洲
this.SetDDlDefaultText(DDLzhou_code, "亚洲");
//验证控件
//this.validate_zhou.Enabled = true;
//this.validate_guojia.Enabled = false;
//this.validate_diqu.Enabled = false;
//this.validate_sheng.Enabled = false;
//this.validate_dijishi.Enabled = false;
//this.validate_xianjishi.Enabled = false;
//选择国家面板=中国
this.DDLzhou_code_SelectedIndexChanged(null, null);
this.Chkzhou_code.Checked = true;
this.Chkzhou_code_CheckedChanged(null, null);
//显示省份面板=未选择
this.DDLguojia_code_SelectedIndexChanged(null, null);
//this.Chkguojia_code.Checked = true;
//this.Chkguojia_code_CheckedChanged(null, null);
}
}
private void BindDDL(DropDownList ddl, DataSet dt, string strValueField, string strTextField)
{
ddl.DataSource = dt;
ddl.DataValueField = strValueField;
ddl.DataTextField = strTextField;
ddl.DataBind();
}
//选择国家代码
protected void DDLguojia_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLdiqu_code.Items.Clear();
this.DDLdiqu_code.Items.Add(new ListItem("请选择地区", "0"));
BindDDL(DDLdiqu_code, new NewMd.Core.WorldCityList().diqu(DDLguojia_code.SelectedValue), "citypostcode", "cityname");
DDLdiqu_code_SelectedIndexChanged(null, null);
}
//选择地区代码.联动
protected void DDLdiqu_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLsheng_code.Items.Clear();
this.DDLsheng_code.Items.Add(new ListItem("请选择省份", "0"));
BindDDL(DDLsheng_code, new NewMd.Core.WorldCityList().sheng(DDLdiqu_code.SelectedValue), "citypostcode", "cityname");
DDLsheng_code_SelectedIndexChanged(null, null);
}
//选择省份代码.联动
protected void DDLsheng_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLdijishi_code.Items.Clear();
this.DDLdijishi_code.Items.Add(new ListItem("请选择地级市", "0"));
BindDDL(DDLdijishi_code, new NewMd.Core.WorldCityList().dijishi(DDLsheng_code.SelectedValue), "citypostcode", "cityname");
DDLdijishi_code_SelectedIndexChanged(null, null);
}
//选择地级市.联动
protected void DDLdijishi_code_SelectedIndexChanged(object sender, EventArgs e)
{
this.DDLxianjishi_code.Items.Clear();
this.DDLxianjishi_code.Items.Add(new ListItem("请选择县级市", "0"));
BindDDL(DDLxianjishi_code, new NewMd.Core.WorldCityList().xianjishi(DDLdijishi_code.SelectedValue), "citypostcode", "cityname");
}
private DropDownList GetSelectCity()
{
DropDownList Retval = DDLzhou_code;
if (Panel6.Visible)
{
return DDLxianjishi_code;
}
if (Panel5.Visible)
{
return DDLdijishi_code;
}
if (Panel4.Visible)
{
return DDLsheng_code;
}
if (Panel3.Visible)
{
return DDLdiqu_code;
}
if (Panel2.Visible)
{
return DDLguojia_code;
}
if (Panel1.Visible)
{
return DDLzhou_code;
}
return Retval;
}
#endregion
//获取城市代码
public NewMd.Model.City_CitySelect_all GetCity()
{
return 选定的城市代码;
}
/// <summary>
/// 提供数据回显的代码
/// </summary>
/// <param name="code">输入城市代码</param>
/// <returns>返回设定是否成功,UI是否回显</returns>
public bool setLocationCode(string code)
{
//安全检查位数
if (code.Length != 9)
{
return false;
}
if (code.Substring(1, 8) != "00000000")
{
this.Chkzhou_code.Checked = true;
this.Chkzhou_code_CheckedChanged(null, null);
}
if (code.Substring(3, 6) != "000000")
{
this.Chkguojia_code.Checked = true;
this.Chkguojia_code_CheckedChanged(null, null);
}
if (code.Substring(4, 5) != "00000")
{
this.Chkdiqu_code.Checked = true;
this.Chkdiqu_code_CheckedChanged(null, null);
}
if (code.Substring(5, 4) != "0000")
{
this.Chksheng_code.Checked = true;
this.Chksheng_code_CheckedChanged(null, null);
}
if (code.Substring(7, 2) != "00")
{
this.Chkdijishi_code.Checked = true;
this.Chkdijishi_code_CheckedChanged(null, null);
}
//绑定洲的代码...1
BindDDL(DDLzhou_code, new NewMd.Core.WorldCityList().zhouByDisp(), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLzhou_code, code.Substring(0, 1) + "00000000");
DDLzhou_code_SelectedIndexChanged(null, null);
//国家2
BindDDL(DDLguojia_code, new NewMd.Core.WorldCityList().guojiaBydisp(code), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLguojia_code, code.Substring(0, 3) + "000000");
DDLguojia_code_SelectedIndexChanged(null, null);
//地区4
BindDDL(DDLdiqu_code, new NewMd.Core.WorldCityList().diqu(code), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLdiqu_code, code.Substring(0, 4) + "00000");
DDLdiqu_code_SelectedIndexChanged(null, null);
//省份5
BindDDL(DDLsheng_code, new NewMd.Core.WorldCityList().sheng(DDLdiqu_code.SelectedValue), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLsheng_code, code.Substring(0, 5) + "0000");
DDLsheng_code_SelectedIndexChanged(null, null);
//地级市7
BindDDL(DDLdijishi_code, new NewMd.Core.WorldCityList().dijishi(DDLsheng_code.SelectedValue), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLdijishi_code, code.Substring(0, 7) + "00");
DDLdijishi_code_SelectedIndexChanged(null, null);
//县级市
BindDDL(DDLxianjishi_code, new NewMd.Core.WorldCityList().xianjishi(DDLdijishi_code.SelectedValue), "citypostcode", "cityname");
this.setDDLDefaultValue(this.DDLxianjishi_code, code);
return true;
}
}
#2
用户控件是否动态加载
if(!IsPostback)
{
//调用this.City_Select_All_In_One1.setLocationCode方法,
参数默认为空值,应该先设置DropDownList国家,地区,省份,再显示Panel
使用ajax通过DropDownList级联选择很简单
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</div>
if(!IsPostback)
{
//调用this.City_Select_All_In_One1.setLocationCode方法,
参数默认为空值,应该先设置DropDownList国家,地区,省份,再显示Panel
使用ajax通过DropDownList级联选择很简单
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
</div>
#3
我的问题是,为何在 测试页面的页面加载初始化时候调用,控件Panel面板就没有反应....不会响应setLocationCode方法....
页面的 Page_Load
s etLocationCode方法用[color=#0000FF]按钮点击事件调用是好的啊[/color]
#4
在调用控件的页面调用setLocationCode(string code)方法
设置下拉框值
设置下拉框值
#5
http://www.cnblogs.com/oletan/archive/2008/11/04/1326587.html
终于解决了问题,爷爷的...生命周期问题...
#region 调用方法事件...初始化控件...
protected override void OnSaveStateComplete(EventArgs e)
{
base.OnSaveStateComplete(e);
this.Web_Site_Select.setSiteCode("Wa", "Wa-80", "Wa-80803");
this.City_Select_All_In_One1.setLocationCode("Ycn330723");
}
#endregion
送分了..................
终于解决了问题,爷爷的...生命周期问题...
#region 调用方法事件...初始化控件...
protected override void OnSaveStateComplete(EventArgs e)
{
base.OnSaveStateComplete(e);
this.Web_Site_Select.setSiteCode("Wa", "Wa-80", "Wa-80803");
this.City_Select_All_In_One1.setLocationCode("Ycn330723");
}
#endregion
送分了..................
#6
你可能没有好好看问题,控件功能已经实现了!
就是调用方法的时候响应问题而已...
#7
执行顺序
控件的Init事件
控件所在页面的Init事件
控件所在页面的Load事件
控件的Load事件
控件所在页面的PreRender事件
控件的PreRender事件
控件的Init事件
控件所在页面的Init事件
控件所在页面的Load事件
控件的Load事件
控件所在页面的PreRender事件
控件的PreRender事件
#8
谢谢哦...有qq吗?
#9
#region SaveStateComplete 第九步
protected override void OnSaveStateComplete(EventArgs e)
我用这个方法,却无法保存控件的状态???
protected override void OnSaveStateComplete(EventArgs e)
我用这个方法,却无法保存控件的状态???
#10
现在好了,,,,,
控件属性
貌似无法存值...会丢失状态...(调用属性之前,已经set这个属性的值了...)
只有用方法才能返回真正的值
public string get*Code()
{
return this.DropDownList.SelectedValue;
}
控件属性
public string *Code
{
get { return _*_code; }
set { this._*_code = value; }
}
貌似无法存值...会丢失状态...(调用属性之前,已经set这个属性的值了...)
只有用方法才能返回真正的值
public string get*Code()
{
return this.DropDownList.SelectedValue;
}
#11
.......