S
s9213037
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 = new FileUpload();
fileUpload.ID = "FileUpload" +
ViewState["noOfFileUploads"].ToString();
fileUpload.Width = Unit.Pixel(800);
this.Upload_Panel.Controls.Add(new LiteralControl("<br>"));
this.Upload_Panel.Controls.Add(fileUpload);
ViewState["noOfFileUploads"] =
(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.
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 = new FileUpload();
fileUpload.ID = "FileUpload" +
ViewState["noOfFileUploads"].ToString();
fileUpload.Width = Unit.Pixel(800);
this.Upload_Panel.Controls.Add(new LiteralControl("<br>"));
this.Upload_Panel.Controls.Add(fileUpload);
ViewState["noOfFileUploads"] =
(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.