How to set hint in htmlcontrol in codebehind in asp.net

I have an html control like

<input id="Button1" type="button" value="button" />
      <input id="Text1" type="text" />
      <img alt="" src="" id="img1"  />

      

I want to set my hint or titrate in code.

I tried the following code but it doesn't work

  Button1.Attributes["tittle"] = "i am button";
   Text1.Attributes["tittle"] = "i am text";
  img1.Attributes["tittle"] = "i am image";

      

it doesn't work please help

+3


source to share


2 answers


Set runat="server"

for each control:

<input id="Button1" runat="server" type="button" value="button" />

      



Then in CodeBehind Page_Load

use this:

Button1.Attributes.Add("title", "i am button");

      

+6


source


You need to mark these items as runat = "server" so the server knows about them. Otherwise, server-side code won't know they exist.



Alternatively, you can add blob javascript to the body of the response message and set the JS attributes. It's stupid and ugly though.

0


source







All Articles