简体   繁体   English

asp.net如何在按钮单击事件中添加动态LinkBut​​ton?

[英]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. 单击提交按钮并将其正确发回后,是否可以添加LinkBut​​ton。 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.

相关问题 在asp.net中为动态按钮添加单击事件 - Add click event for a dynamic button in asp.net LinkBut​​ton 单击事件未触发 asp.net - LinkButton click event not firing asp.net ASP.NET Linkbutton不触发click事件 - ASP.NET Linkbutton not firing click event 如何在按钮单击时在asp.net中添加具有不同ID并具有不同Click事件的动态控件? - How to add dynamic controls with different ID and having a different Click event in asp.net on a button click? 如何通过单击另一页面的链接按钮来调用按钮的单击事件,而无需在c#ASP.NET中回发 - How to call button's click event from click of linkbutton of another page without post back in c# ASP.NET 如何在驻留在ASP.NET GridView中的ASP.NET LinkBut​​ton的click事件中显示消息? - How to disply message upon the click event of ASP.NET LinkButton residing inside ASP.NET GridView? 如何使用vb在asp.net中添加按钮单击事件 - how to add Button Click Event in asp.net with vb 如何在asp.net linkBut​​ton中添加图像按钮? - how to add imagebutton in asp.net linkButton? 请检查我的代码以添加linkbutton并在asp.net中以编程方式单击事件 - Please check my code to add linkbutton and click event programmatcally in asp.net 动态LinkBut​​ton OnClick事件在ASP.Net上不起作用 - dynamic LinkButton OnClick event not working on ASP.Net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM