3

I have a html control like

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

i want to set its tooltip or tittle in codebehind .

I tried the following code but its not working

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

this is not working please help

1
  • "tiTTle..."? :-) Commented Jan 29, 2021 at 12:07

2 Answers 2

8

Set runat="server" for each control:

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

Then in CodeBehind in Page_Load use this:

Button1.Attributes.Add("title", "i am button");
Sign up to request clarification or add additional context in comments.

1 Comment

Note: Button1.Attributes.Add("tittle".... Should be Button1.Attributes.Add("title"... I tried to edit, but SO editing rules require at least six characters to be changed.
0

You need to mark those elements as runat="server" so that the server knows about them. Otherwise, server-side code won't be aware that they exist.

Alternatively, you could add a blob of javascript to the response message body and have the JS set the attributes. That's silly and ugly, though.

1 Comment

i had marked the element as runat=server ,but still its not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.