【发布时间】:2020-07-14 19:20:44
【问题描述】:
我在驱动器 E 中列出文件夹和文件,我使用隐藏字段来保留路径,我创建了一些代表文件夹的链接按钮,它们是在 Page_PreLoad() 事件中以编程方式创建的:
protected void Page_PreLoad(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(hdfPath.Value))
{
path = "E:\\" + hdfPath.Value;
directories = Directory.GetDirectories(path);
files = Directory.GetFiles(path);
}
else
{
directories = Directory.GetDirectories("E:\\");
files = Directory.GetFiles("E:\\");
}
for (int i = 0; i < directories.Length; i++)
{
LinkButton lkbLink = new LinkButton();
lkbLink.Click += new EventHandler(btn_Click);
void btn_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(hdfPath.Value))
hdfPath.Value = folderName;
else
hdfPath.Value += "\\" + folderName;
}
}
}
当我单击任何链接按钮时,首先触发 Page_PreLoad() 事件,然后触发 btn_Click() 事件,而我希望首先触发 btn_Click()。那么隐藏字段的相关值就属于前一步的值。
我选择的 ASP.Net 生命周期有问题吗?
如何在用户单击链接按钮时立即设置隐藏字段值,以便获取隐藏字段上的(正确)当前值?
【问题讨论】: