我有一个允许用户上传文件并在GridView中显示它们的UserControl。在父页面上,我有一个jQuery选项卡控件,我在其中动态添加了我的UserControl的两个实例(在不同的选项卡上)。第二个实例运行得很好,所以我知道控件可以工作。然而,当我尝试使用第一个实例上传文件时,第二个实例被referenced...so所有属性值、控件名称等指向第二个实例的值。
这就是我在父页面代码隐藏中加载控件的方式:
protected void Page_Load(object sender, EventArgs e)
{
MyControl ucAttachments1 = (MyControl) Page.LoadControl("~/controls/mycontrol.ascx");
ucAttachments1.ID = "ucAttachments1";
ucAttachments1.Directory = "/uploads/documents";
ucAttachments1.DataChanged += new MyControl.DataChangedEventHandler(DoSomething);
phAttachments1.Controls.Add(ucAttachments1);
MyControl ucAttachments2 = (MyControl)Page.LoadControl("~/controls/mycontrol.ascx");
ucAttachments2.ID = "ucAttachments2";
ucAttachments2.Directory = "/uploads/drawings";
ucAttachments2.DataChanged += new MyControl.DataChangedEventHandler(DoSomething);
phAttachmetns2.Controls.Add(ucAttachments2);
}在html中:
<div id="tabContainer">
<div id="files">
<asp:PlaceHolder id="phAttachments1" runat="server" />
</div>
<div id="drawings">
<asp:PlaceHolder id="phAttachments2" runat="server" />
</div>
</div>用户控件代码的一个片段:
private string directory;
override protected void OnLoad(EventArgs e)
{
PopulateAttachmentGridview();
}
protected btnUpload_Click(object sender, EventArgs e)
{
UploadFile(directory);
}
public string Directory
{
get { return directory; }
set { directory = value; }
}如何确保我的用户控件被正确引用?
发布于 2011-06-01 12:40:11
检查呈现给客户端的实际html和javascript,以确保没有与控件相关的重复ID。
https://stackoverflow.com/questions/6196096
复制相似问题