2012-11-29 3 views
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); 
} 

이 문제를 해결하는 데 유용한 아이디어가 있습니까? 나는 웹을 둘러 보았고 페이지 수명주기에 대해 꽤 괜찮은 생각을하고 있다고 생각합니다. 그러나 이것은 성가신 일입니다. 나는이 문제들에 더 자주 빠지지 않는 것 같다.

답변

0

처음에는 LinkButton pDelete을 추가 할 수 있지만 클릭하면 표시 및 기타 속성을 설정하면 항상 존재하며 문제가 사라집니다.

+0

시도했지만 명령 이벤트 중에 commandargument 및 commandname 필드가 없습니다. –

관련 문제