*.aspx文件:
...
this.myPanel.Controls.Add(Page.LoadControl("customerCtl.ascx"));
...
(50分)
在页面上加载了多个customerCtl.ascx控件后,怎么识别ascx中的同一个web控件呢?
如:customerCtl.ascx中有
<asp:DropDownList ID="FiledDDL" Runat="server">
在aspx中如何定位到具体的某个DropDownList 控件呢?
(50)
还请各位高手指点
6 个解决方案
#1
关于第一个问题,用了其它写法也没用
我在customerCtl文件中加了一个Panel控件以便把两个DropDownList和一个textbox控件包含在一起.
Control myPanel = LoadControl("customerCtl.ascx");
SearchTermPanel.Controls.AddAt(CtlCount,myPanel);
我在customerCtl文件中加了一个Panel控件以便把两个DropDownList和一个textbox控件包含在一起.
Control myPanel = LoadControl("customerCtl.ascx");
SearchTermPanel.Controls.AddAt(CtlCount,myPanel);
#2
you need to load it multiple times, give it an ID and use FindControl, for example:
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
Control c = LoadControl("customerCtl.ascx");
c.ID = "hello";
form1.Controls.Add(c);
c = LoadControl("customerCtl.ascx");
c.ID = "world";
form1.Controls.Add(c);
DropDownList dd = (DropDownList)FindControl("hello").FindControl("FiledDDL");
dd.Items.Add("hello");
DropDownList dd2 = (DropDownList)FindControl("world").FindControl("FiledDDL");
dd2.Items.Add("world");
}
</script>
<html>
<head>
</head>
<body>
<form runat="server" id="form1">
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
Control c = LoadControl("customerCtl.ascx");
c.ID = "hello";
form1.Controls.Add(c);
c = LoadControl("customerCtl.ascx");
c.ID = "world";
form1.Controls.Add(c);
DropDownList dd = (DropDownList)FindControl("hello").FindControl("FiledDDL");
dd.Items.Add("hello");
DropDownList dd2 = (DropDownList)FindControl("world").FindControl("FiledDDL");
dd2.Items.Add("world");
}
</script>
<html>
<head>
</head>
<body>
<form runat="server" id="form1">
</form>
</body>
</html>
#3
study!
#4
非常感谢!
#5
非常感谢!
#6
"贴子回复次数大于跟给分次数"
我要结贴,但是出现上面的提示,怎么办?
我要结贴,但是出现上面的提示,怎么办?
#1
关于第一个问题,用了其它写法也没用
我在customerCtl文件中加了一个Panel控件以便把两个DropDownList和一个textbox控件包含在一起.
Control myPanel = LoadControl("customerCtl.ascx");
SearchTermPanel.Controls.AddAt(CtlCount,myPanel);
我在customerCtl文件中加了一个Panel控件以便把两个DropDownList和一个textbox控件包含在一起.
Control myPanel = LoadControl("customerCtl.ascx");
SearchTermPanel.Controls.AddAt(CtlCount,myPanel);
#2
you need to load it multiple times, give it an ID and use FindControl, for example:
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
Control c = LoadControl("customerCtl.ascx");
c.ID = "hello";
form1.Controls.Add(c);
c = LoadControl("customerCtl.ascx");
c.ID = "world";
form1.Controls.Add(c);
DropDownList dd = (DropDownList)FindControl("hello").FindControl("FiledDDL");
dd.Items.Add("hello");
DropDownList dd2 = (DropDownList)FindControl("world").FindControl("FiledDDL");
dd2.Items.Add("world");
}
</script>
<html>
<head>
</head>
<body>
<form runat="server" id="form1">
</form>
</body>
</html>
<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object o, EventArgs e)
{
Control c = LoadControl("customerCtl.ascx");
c.ID = "hello";
form1.Controls.Add(c);
c = LoadControl("customerCtl.ascx");
c.ID = "world";
form1.Controls.Add(c);
DropDownList dd = (DropDownList)FindControl("hello").FindControl("FiledDDL");
dd.Items.Add("hello");
DropDownList dd2 = (DropDownList)FindControl("world").FindControl("FiledDDL");
dd2.Items.Add("world");
}
</script>
<html>
<head>
</head>
<body>
<form runat="server" id="form1">
</form>
</body>
</html>
#3
study!
#4
非常感谢!
#5
非常感谢!
#6
"贴子回复次数大于跟给分次数"
我要结贴,但是出现上面的提示,怎么办?
我要结贴,但是出现上面的提示,怎么办?