如何仅使用 FileUpload 代码隐藏上传?我的控件是代码隐藏的,因为我有 Dropdown_SelectedIndexChanged 并且需要生成各种数量的控件。我可以很好地列出控件并将文件和文本附加到txtbox:
private void SetChildrenCountControls(int total)
{
for (int i = 0; i < total; i++)
{
var tbBirthDate = new TextBox();
tbBirthDate.ID = "tbBirthDate_" + (i + 1);
tbBirthDate.CssClass = "tbSister_input";
tbBirthDate.EnableViewState = true;
FileUpload upload = new FileUpload();
upload.ID = "imgUpload_" + (i + 1);
upload.CssClass = "tbSister_upload";
upload.EnableViewState = true;
ChildrenCountTextPanel.Controls.Add(tbBirthDate);
ChildrenCountTextPanel.Controls.Add(upload);
}
}
并且可以通过以下方式获取 txtbox 中输入的文本:
protected void lbFamilySave_Click(object sender, EventArgs e)
{
var countSisters = ChildrenCountTextPanel.Controls.OfType<TextBox>();
string sisterBirth = string.Empty;
foreach (var sister in countSisters)
{
if (sister.ID.Contains("tbBirthDate_"))
sisterBirth = sister.Text;
}
}
如何从 FileUpload 控件获取文件?似乎无法使用 FileUpload 完成上述操作。