0
是否有一種方法可以在單擊提交按鈕後添加LinkButton並將其正確回發。以這種情況爲例。asp.net如何在按鈕點擊事件中添加動態LinkButton?
頁面上載有上傳控件和提交按鈕。選擇完成後,用戶單擊「提交」按鈕,我想在另一個分隔欄中顯示已上載的文件,並在文件名旁邊顯示一個可選的刪除按鈕。問題是,當用戶點擊提交按鈕時,我嘗試在點擊處理程序上添加控件,因爲這是請求文件的地方,但是當我嘗試在控件響應中添加一個鏈接按鈕,並且當然事件不掛鉤。
<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);
}
有沒有人有什麼好的想法來解決這個問題?我瀏覽了所有網頁,我認爲我對頁面生命週期有相當不錯的把握。但這很煩人。我似乎更多時候會遇到這些問題。
我試過了,但commandargument和commandname字段在命令事件中不存在。 –