使用代码隐藏控制 ImageButton 中的名称属性
我有一个 ImageButton,我想更改代码隐藏中的 NAME 属性,以便我可以根据需要呈现 HTML。
当前的渲染是:
<input id="MainContent_GridViewTracking_ibOrderDetail_15" class="smIcon" type="image" src="../Images/icons/img_page.png" text="Details" name="ctl00$MainContent$GridViewTracking$ctl17$ibOrderDetail">
我想使用代码隐藏来控制名称,将其分配给 track.myID ,这将导致类似
<input id="MainContent_GridViewTracking_ibOrderDetail_15" class="dhIcon" type="image" src="../Images/icons/doc_page.png" text="Details" name="1654874">
TIA 的结果
I have an ImageButton which I want to change the NAME attribute of in the code-behind so that I can render the HTML as needed.
The current Rendering is :
<input id="MainContent_GridViewTracking_ibOrderDetail_15" class="smIcon" type="image" src="../Images/icons/img_page.png" text="Details" name="ctl00$MainContent$GridViewTracking$ctl17$ibOrderDetail">
I would like to control the NAME using code-behind as assign it to track.myID which would result with something like
<input id="MainContent_GridViewTracking_ibOrderDetail_15" class="dhIcon" type="image" src="../Images/icons/doc_page.png" text="Details" name="1654874">
TIA
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过
MyImageButtons.Attributes["name"]=xyz
?应该到窍门。或者您可以向其添加任何其他属性,如下所示:MyImageButton.Attributes.Add("trackID", xyz)
并将该属性用于您想要使用的任何内容。或者,如果您不想使用其他属性,您可以使用 jQuery 获取其他属性的值并将其设置为名称值。Have you tried
MyImageButtons.Attributes["name"]=xyz
? Should to the trick. Or you could add any other attribute to it like so:MyImageButton.Attributes.Add("trackID", xyz)
and use that atribute for whatever you want to use. Or if you don't want to use that other attribute you could use jQuery to grab that other attribute's value and set it as name value.将 runat="server" 放入 html 中,然后您就可以在代码隐藏中访问它。
喜欢:
put runat="server" in the html, then you'll have access to it in the codebehind.
like: