[英]Control the Name Attribute within an ImageButton using code-behind
我有一個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">
我想使用代碼隱藏來控制NAME,因為將其分配給track.myID會導致類似
<input id="MainContent_GridViewTracking_ibOrderDetail_15" class="dhIcon" type="image" src="../Images/icons/doc_page.png" text="Details" name="1654874">
TIA
您是否嘗試過MyImageButtons.Attributes["name"]=xyz
? 應該是把戲。 或者,您可以像這樣MyImageButton.Attributes.Add("trackID", xyz)
添加任何其他屬性: MyImageButton.Attributes.Add("trackID", xyz)
並將該屬性用於您要使用的任何屬性。 或者,如果您不想使用該其他屬性,則可以使用jQuery來獲取該其他屬性的值並將其設置為名稱值。
將runat =“ server”放在html中,那么您將可以在后面的代碼中訪問它。
喜歡:
<input id="MainContent_GridViewTracking_ibOrderDetail_15"
runat="server"
class="smIcon"
type="image"
src="../Images/icons/img_page.png"
text="Details"
name="ctl00$MainContent$GridViewTracking$ctl17$ibOrderDetail">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.