.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctlInvestType.ascx.cs" Inherits="Controls_ctlInvestType" %>
<%@ OutputCache Duration="3600" VaryByParam="None"%>
<asp:DropDownList ID="ddlInvestType" runat="server">
<asp:ListItem>上级资金支持</asp:ListItem>
<asp:ListItem>银行贷款</asp:ListItem>
<asp:ListItem>自筹</asp:ListItem>
<asp:ListItem>其它</asp:ListItem>
</asp:DropDownList>.ascx.cs
public partial class Controls_ctlInvestType : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{ } public string SelectedValue
{
get { return ddlInvestType.SelectedValue; }
set { ddlInvestType.SelectedValue = value; }
}
}
我在引用控件的页面中 调用 SelectedValue 提示“未将对象初始化”
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctlInvestType.ascx.cs" Inherits="Controls_ctlInvestType" %>
<%@ OutputCache Duration="3600" VaryByParam="None"%>
<asp:DropDownList ID="ddlInvestType" runat="server">
<asp:ListItem>上级资金支持</asp:ListItem>
<asp:ListItem>银行贷款</asp:ListItem>
<asp:ListItem>自筹</asp:ListItem>
<asp:ListItem>其它</asp:ListItem>
</asp:DropDownList>.ascx.cs
public partial class Controls_ctlInvestType : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{ } public string SelectedValue
{
get { return ddlInvestType.SelectedValue; }
set { ddlInvestType.SelectedValue = value; }
}
}
我在引用控件的页面中 调用 SelectedValue 提示“未将对象初始化”
{
get { return ddlInvestType.SelectedValue; }
set { ddlInvestType.SelectedValue = value; }
}
你没定义DropDownList的value值,用ddlInvestType.text
{
get { EnsureChildControls(); return ddlInvestType.SelectedValue; }
set { EnsureChildControls(); ddlInvestType.SelectedValue = value; }
}
<asp:DropDownList ID="ddlInvestType" runat="server">
<asp:ListItem Value="">上级资金支持 </asp:ListItem>
<asp:ListItem Value="">银行贷款 </asp:ListItem>
<asp:ListItem Value="">自筹 </asp:ListItem>
<asp:ListItem Value="">其它 </asp:ListItem>
</asp:DropDownList>
你没定义value值所以不能用SelectedValue
public class UserControl
{
public UserControl()
{
}......
}
.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ctlInvestType.ascx.cs" Inherits="Controls_ctlInvestType" %>
<%@ OutputCache Duration="3600" VaryByParam="None"%>
<asp:DropDownList ID="ddlInvestType" runat="server">
<asp:ListItem value="上级资金支持" text="上级资金支持">上级资金支持 </asp:ListItem>
<asp:ListItem value="银行贷款" text="银行贷款">银行贷款 </asp:ListItem>
<asp:ListItem value="自筹" text="自筹">自筹 </asp:ListItem>
<asp:ListItem value="其它" text="其它">其它 </asp:ListItem>
</asp:DropDownList> .ascx.cs
public partial class Controls_ctlInvestType : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{ } public string SelectedValue
{
get { return ddlInvestType.SelectedValue; }
set { ddlInvestType.SelectedValue = value; }
}
}
参考
http://www.cnblogs.com/luca623/archive/2008/07/01/1233045.html
吧<%@ OutputCache Duration="3600" VaryByParam="None"%> 注释掉 就可以了
应该是 缓存的事吧