首先建立一个页面 里面放一个用户控件city1.ascx
在city1.ascx用户控件中 创建一个属性
public string ParamName
{
get
{
if (string.IsNullOrEmpty(HiddenFieldParam.Value))
{
HiddenFieldParam.Value = ParamName;
return HiddenFieldParam.Value;
}
return null;
}
set { HiddenFieldParam.Value = value; }
}
然后我在调用city1.ascx的页面中写着这么一行代码
city1 ct1 = new city1();
if (!string.IsNullOrEmpty(ct1.ParamName))
{
city2 ct2 = new city2();
ct2.Val = ct1.ParamName;
}
运行后 告诉我 if (string.IsNullOrEmpty(HiddenFieldParam.Value)) 未将对象引用到实例
在city1.ascx用户控件中 创建一个属性
public string ParamName
{
get
{
if (string.IsNullOrEmpty(HiddenFieldParam.Value))
{
HiddenFieldParam.Value = ParamName;
return HiddenFieldParam.Value;
}
return null;
}
set { HiddenFieldParam.Value = value; }
}
然后我在调用city1.ascx的页面中写着这么一行代码
city1 ct1 = new city1();
if (!string.IsNullOrEmpty(ct1.ParamName))
{
city2 ct2 = new city2();
ct2.Val = ct1.ParamName;
}
运行后 告诉我 if (string.IsNullOrEmpty(HiddenFieldParam.Value)) 未将对象引用到实例
<asp:DropDownList ID="ddlcity1" runat="server"
AutoPostBack="True">
</asp:DropDownList>
<asp:HiddenField ID="HiddenFieldParam" runat="server" Value="" />