当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Control the Name Attribute within an ImageButton using code-behind

问题描述:

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

网友答案:

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.

网友答案:

put runat="server" in the html, then you'll have access to it in the codebehind.

like:

<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">
分享给朋友:
您可能感兴趣的文章:
随机阅读: