[英]asp.net How to add dynamic LinkButton in the button click event?
Is there a way to add LinkButton after a submit button is clicked and have it post back correctly. 单击提交按钮并将其正确发回后,是否可以添加LinkButton。 Take this scenario for instance.
以这种情况为例。
A page is loaded with an upload control on it and a submit button. 页面上加载了一个上载控件和一个提交按钮。 After a selection is made and the user clicks the submit button, I would like to show in another divider the files that have been uploaded with an optional remove button beside the file name.
做出选择并用户单击“提交”按钮后,我想在另一个分隔符中显示已上传的文件,并在文件名旁边显示一个可选的“删除”按钮。 The issue is that when the user clicks the submit button I try to add the controls on the click handler because that is where the file is requested but when I try to add a linkbutton in the control response and the events of course do not hook up.
问题是,当用户单击“提交”按钮时,我尝试在单击处理程序上添加控件,因为那是请求文件的位置,但是当我尝试在控件响应中添加链接按钮时,事件当然也不会挂断。
<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);
}
Does any one have any good ideas to solve this? 有谁有解决这个问题的好主意吗? I have looked all around the web and I think I have a fairly decent grasp on the page lifecycle.
我在网上浏览了所有内容,我认为我对页面生命周期有相当不错的了解。 But this is annoying.
但这很烦人。 I seem to get stuck with these issues more often than not.
我似乎经常被这些问题困扰。
您LinkButton pDelete
在开始时添加LinkButton pDelete
,但是在“单击”上将其设置为“可见”和其他属性,则它将始终存在并且问题将消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.