Ravi Ram
Ravi Ram

Reputation: 24488

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

Upvotes: 1

Views: 1417

Answers (2)

Dimitri
Dimitri

Reputation: 7013

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.

Upvotes: 1

Chuck Savage
Chuck Savage

Reputation: 11955

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">

Upvotes: 0

Related Questions