【问题标题】:asp.net How to add dynamic LinkButton in the button click event?asp.net如何在按钮点击事件中添加动态LinkBut​​ton?
【发布时间】:2012-11-29 17:44:48
【问题描述】:

有没有办法在点击提交按钮后添加 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);
}

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

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    你能不能在开头加上LinkButton pDelete,但是在点击时设置它Visible和其他属性,那么它就会一直存在,问题就会消失。

    【讨论】:

    • 我试过了,但是在命令事件期间命令参数和命令名称字段不存在。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多