0

有没有办法在单击提交按钮后添加 LinkBut​​ton 并让它正确回发。以这种情况为例。

页面加载了一个上传控件和一个提交按钮。做出选择并且用户单击提交按钮后,我想在另一个分隔符中显示已上传的文件,并在文件名旁边使用可选的删除按钮。问题是,当用户单击提交按钮时,我尝试在单击处理程序上添加控件,因为这是请求文件的位置,但是当我尝试在控件响应中添加链接按钮时,事件当然不会挂钩.

<form .....
<telerik:RadAsyncUpload ID="CtrlRadAsyncUpload" runat="server">
</telerik:RadAsyncUpload>
<asp:Button ID="CtrlSave" runat="server" Text="Submit Plans" />


protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    CtrlSave.Click += new EventHandler(CtrlSave_Click);
}

protected void Page_Load(object sender, EventArgs e)
{
 //the problem is here, the new files are not created until after telerik has processed it own button click. I could add the buttons here, but the files are not posted yet. So i try to add them in the button click event. see below.
}

void CtrlSave_Click(object sender, EventArgs e)
{
 any LinkButtons created and added to the controls collection are there, but they do not post back properly

 //get uploaded data
 LinkButton pDelete = new LinkButton();
            pDelete.Text = "Remove";
            pDelete.Command += new CommandEventHandler(pDelete_Command);
            pDelete.CommandArgument = pFile;
            pDelete.CommandName = "Delete";
            Controls.Add(pDelete);
}

有没有人有解决这个问题的好主意?我浏览了整个网络,我认为我对页面生命周期有相当不错的掌握。但这很烦人。我似乎经常被这些问题困住。

4

1 回答 1

0

您可以LinkButton pDelete在开始时添加,但是在单击时将其设置为可见和其他属性,那么它将始终存在并且问题将消失。

于 2012-11-29T09:44:48.270 回答