【发布时间】:2014-07-24 16:14:00
【问题描述】:
所以基本上我在 Div 元素内使用 for 循环创建 ImageButtons,
但是我在创建此 ImageButtons 时设置的 onclick 功能不起作用并且它不会传输。所以我想我没有正确添加该功能,尽管下面的按钮功能工作正常
protected void Page_Load(object sender, EventArgs e)
{
foreach (string strFileName in Directory.GetFiles(Server.MapPath("~/path/")))
{
ImageButton imageButton = new ImageButton();
FileInfo fileInfo = new FileInfo(strFileName);
imageButton.ImageUrl = "~/path/" + fileInfo.Name.ToString();
imageButton.Attributes.Add("ID" , strFileName);
imageButton.Attributes.Add("class","imgOne");
imageButton.Attributes.Add("runat", "server");
imageButton.Attributes.Add("OnClick", "toImageDisplay");
photos.Controls.Add(imageButton);
}
}
public void toImageDisplay()
{
Server.Transfer("ImageDisplay.aspx");
}
protected void Unnamed1_Click(object sender, EventArgs e)
{
toImageDisplay();
}
【问题讨论】:
标签: c# javascript asp.net webforms