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属性。

相关内容

热门资讯

透视ai!wepoker是不是... 透视ai!wepoker是不是有人用挂(透视)本来是有辅助工具(今日头条)-哔哩哔哩1、每一步都需要...
据公告内容!wepoker透视... 据公告内容!wepoker透视脚本免费(透视)果然真的是有辅助修改器(有挂教程)-哔哩哔哩1、wep...
值得注意的是!约局吧app有挂... 值得注意的是!约局吧app有挂吗(透视)原来真的有辅助辅助器(有挂解惑)-哔哩哔哩1)约局吧app有...
据统计!xpoker透视辅助(... 据统计!xpoker透视辅助(透视)总是有辅助下载(真的有挂)-哔哩哔哩该软件可以轻松地帮助玩家将x...
透视智能ai!wpk免费辅助(... 透视智能ai!wpk免费辅助(透视)本来有辅助安装(有挂工具)-哔哩哔哩一、wpk免费辅助游戏安装教...
透视能赢!wepoker作必弊... 透视能赢!wepoker作必弊视频(透视)其实有辅助修改器(有挂教学)-哔哩哔哩1、wepoker作...
此事迅速冲上热搜!wepoke... 此事迅速冲上热搜!wepoker有辅助吗(透视)竟然真的有辅助插件(有挂秘诀)-哔哩哔哩一、wepo...
近日!智星德州插件(透视)一直... 近日!智星德州插件(透视)一直存在有辅助平台(有挂神器)-哔哩哔哩1、金币登录送、破产送、升级送、活...
透视中牌率!wepokerpl... 透视中牌率!wepokerplus开挂(透视)真是存在有辅助平台(今日头条)-哔哩哔哩;透视中牌率!...
透视苹果版!wepoker破解... 透视苹果版!wepoker破解版内购(透视)竟然存在有辅助app(有挂详细)-哔哩哔哩1、操作简单,...