复合控件中动态生成DropDownList,其数据及选择的是那项是否要记下来下次CreateChildControls中使用便于恢复状态?
能自动恢复状态吗? 问题点数:0、回复次数:3Top
1 楼saucer(思归)回复于 2003-02-02 12:10:22 得分 0
yes, if you make sure CreateChildControls is called before LoadViewState occurs, for example, in Page_Init, call
YourCompositeControlID.FindControl("Whatever");
Top
2 楼luojizi(尘封)回复于 2003-02-02 12:51:26 得分 0
很对不起,我不明白你的“yes”是回答
是能自动恢复状态
还是要记下状态用于下次重现?Top
3 楼saucer(思归)回复于 2003-02-02 14:07:09 得分 0
play with
1. MyComposite.cs: (compile it into MyComposite.dll and copy it to the bin subdirectory)
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyCompositeNamespace {
public class MyComposite : Control, INamingContainer {
protected override void CreateChildControls()
{
DropDownList ddl = new DropDownList();
ddl.ID = "DropDownList1";
for (int i=1; i <= 10; i++)
ddl.Items.Add(i.ToString());
this.Controls.Add(ddl);
}
}
}
2. MyComposite.aspx:
<%@ Register TagPrefix="my" Namespace="MyCompositeNamespace" Assembly="MyComposite" %>
<script language="C#" runat=server>
void Page_Init(Object sender, EventArgs e)
{
//to make sure the controls inside MyControl are created first, uncomment the following line
// MyControl.FindControl("whatever");
}
</script>
<html>
<body>
<form runat=server>
<my:MyComposite id="MyControl" runat="server"/>
<br/>
<asp:button id="Btn" text="submit" runat=server/>
</form>
</body>
</html>
Top




