On 3=A4=EB22=A4=E9, =A4U=A4=C82=AE=C901=A4=C0, "Masudur" <munn...@gmail.com=
> wrote:
> On Mar 22, 10:48 am, s9213...@gmail.com wrote:
>
>
>
>
>
> > Use case scenario:
>
> > I have a panel with ID "Upload_Panel", where there is a FileUpload
> > control with ID "FileUpload1" and a button with ID
> > "More_Upload_Files", both of which are added at design time.
>
> > When users click the "More_Upload_Files" button, a new FileUpload with
> > ID "FileUpload2" control will be added into "Upload_Panel"
> > dynamically.
>
> > Probelm:
>
> > The first added FileUpload (FileUpload2) work fine. However, when
> > users further add more FileUploads, the subsequent generated
> > FileUploads will replace the FileUpload2, rather than added to the
> > "Upload_Panel". In other words, FileUpload3 will replace FileUpload2,
> > FileUpload4 will replace FileUpload3 and so forth. The source code is
> > listed as follows.
>
> > ***********************************************************************=
****-***************
>
> > protected void More_Upload_Files_Button_Click(object sender,
> > EventArgs e)
> > {
> > FileUpload fileUpload =3D new FileUpload();
> > fileUpload.ID =3D "FileUpload" +
> > ViewState["noOfFileUploads"].ToString();
> > fileUpload.Width =3D Unit.Pixel(800);
> > this.Upload_Panel.Controls.Add(new LiteralControl("<br>"));
> > this.Upload_Panel.Controls.Add(fileUpload);
>
> > ViewState["noOfFileUploads"] =3D
> > (int)ViewState["noOfFileUploads"] + 1;
> > }
>
> > ***********************************************************************=
****-***************
>
> > Is there any state-related issue I ignore so that
> > Upload_Panel.Controls connlection is not persistent.
>
> > Any reply would be great appreciated.
>
> > Regards.
>
> Hi...
>
> Dynamically loaded controls do not persists in page... after post
> back...
> you need to repopulate the controls again....
>
> Try adding the controls in page init...
> each time the page is posted to server...
>
> and don't for get to clear the control place holder....
> Page_Init()
> {
> this.Upload_Panel.Controls.Clear();
> int NoofUploadControls =3D (int)ViewState["noOfFileUploads"];
> for(int i=3D0; i<NoofUploadControls ; i++)
> {
> FileUpload fileUpload =3D new FileUpload();
> fileUpload.ID =3D "FileUpload" + i.ToString();
> fileUpload.Width =3D Unit.Pixel(800);
> this.Upload_Panel.Controls.Add(new LiteralControl("<br>"));
> this.Upload_Panel.Controls.Add(fileUpload);
>
> }
> }
>
> Now one more thing...
> Since the control of upload_Panel get Clear...
>
> You got to keep the command button and initial file upload control out
> side the panel....
>
> Thanks...
> Masudur
http://www.kaz.com.bdhttp://munnacs.blogspot.com- =C1=F4=C2=C3=B3Q=
=A4=DE=A5=CE=A4=E5=A6r -
>
> - =C5=E3=A5=DC=B3Q=A4=DE=A5=CE=A4=E5=A6r -
Thanks a lot. Your reply save me much survey time