[英]Find out the id of the anchor tag which has been clicked
这些定位标记在运行时创建。 有4个锚定标记,当它们中的任何一个被单击时,应用程序都被重定向到同一页面,但是我的问题是我是否知道单击了锚定标记(a1 / a2 / a3 / a4)。 我想要已被单击的锚标记的ID,并记得在运行时正在创建锚标记。 感谢您的时间。
PlaceHolder1.Controls.Add(new LiteralControl("<a id='a1' rel='facebox' display='block' href='info.aspx'>Click1</a>"));
PlaceHolder1.Controls.Add(new LiteralControl("<a id='a2' rel='facebox' display='block' href='info.aspx'>Click2</a>"));
PlaceHolder1.Controls.Add(new LiteralControl("<a id='a3' rel='facebox' display='block' href='info.aspx'>Click3</a>"));
PlaceHolder1.Controls.Add(new LiteralControl("<a id='a4' rel='facebox' display='block' href=info.aspx'>Click4</a>"));
一种解决方案是按以下方式创建锚点-
for (int i = 1; i < 5; i++)
{
var htmlanchor = new HtmlAnchor
{
ID = "Click_ID" + i,
HRef = "#info",
InnerText = "Click" + i
};
htmlanchor.ServerClick += new EventHandler(htmlanchor_ServerClick);
PlaceHolder1.Controls.Add(htmlanchor);
}
事件处理程序将是-
void htmlanchor_ServerClick(object sender, EventArgs e)
{
Response.Write(((System.Web.UI.Control)(sender)).UniqueID); // This will print id of anchor button you clicked
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.