ASP.NET如何获取动态生成元素的属性?
创始人
2024-11-12 07:00:24
0

在ASP.NET中,可以使用FindControl方法来查找已生成的动态元素,并获取其属性。下面是一个示例:

1.在ASPX页面中添加一个控件:

2.在代码后端生成动态控件: protected void Page_Load(object sender, EventArgs e) { Literal newLiteral = new Literal(); newLiteral.Text = "Dynamic Element"; ltlDynamic.Controls.Add(newLiteral); }

3.使用FindControl方法查找元素并获取其属性: protected void btnGetAttribute_Click(object sender, EventArgs e) { HtmlGenericControl dynamicElement = (HtmlGenericControl)ltlDynamic.FindControl("dynamicElement"); string elementClass = dynamicElement.Attributes["class"]; string elementDataValue = dynamicElement.Attributes["data-value"]; // do something with the element attributes }

在上面的示例中,我们首先在ASPX页面中添加了一个Literal控件,在Page_Load事件中生成一个动态元素并添加到Literal控件中。然后,我们使用FindControl方法查找生成的元素,并使用Attributes属性获取元素的class和data-value属性。

相关内容

热门资讯

透视教材!hhpoker怎么防... 透视教材!hhpoker怎么防作必弊,hhpoker可以开挂吗(透视)本来有挂(哔哩哔哩)hhpok...
透视妙招!aapoker插件下... 透视妙招!aapoker插件下载,aapoker辅助软件合法吗(透视)原来存在有透视插件(哔哩哔哩)...
透视指南书!竞技联盟破解版最新... 透视指南书!竞技联盟破解版最新版,德普之星透视辅助插件(透视)原来真的是有挂(哔哩哔哩)德普之星透视...
透视妙计!德普辅助软件,德普之... 透视妙计!德普辅助软件,德普之星透视(透视)确实存在有透视工具(哔哩哔哩)1、德普之星透视透视辅助软...
透视模板!拱趴大菠萝挂怎么安装... 透视模板!拱趴大菠萝挂怎么安装,hhpoker辅助(透视)本来真的有挂(哔哩哔哩)1、透视模板!拱趴...
透视课程!epoker免费透视... 透视课程!epoker免费透视脚本,拱趴大菠萝万能挂(透视)好像是有脚本技巧(哔哩哔哩)1、用户打开...
透视窍门!aapoker辅助怎... 透视窍门!aapoker辅助怎么用,wepoker怎么设置透视(透视)竟然真的有挂(哔哩哔哩)小薇(...
透视烘培!epoker底牌透视... 透视烘培!epoker底牌透视,德州局透视脚本下载安装最新版本(透视)竟然有透视攻略(哔哩哔哩)该软...
透视办法!we poker免费... 透视办法!we poker免费辅助器,wepoker私局辅助(透视)一直是有挂(哔哩哔哩)1、玩家可...
透视妙计!wepoker有辅助... 透视妙计!wepoker有辅助插件吗,wepoker手机版辅助(透视)一直有脚本工具(哔哩哔哩)1)...