Andre Pena
Andre Pena

Reputation: 59426

What's the best way to set HTML tags visible and invisible at code-behind?

I have a Change Password page that has a H2 HTML tag that says "The password has been successfuly changed". This H2 tag, however, needs to be visible only on success. That is: I want to manually activate it (Visible=true) in the "Change password" button click postback event.

The question is: What's the best way to control this H2 tag visibility via code-behind?

I thought of adding it to a PlaceHolder control so that I can change it's visible property but it does not seems right as it's not the purpose of the control.

PS: I don't want to add it to a panel as the panel will add additional markup to the rendered page.

Upvotes: 2

Views: 1137

Answers (1)

Sapph
Sapph

Reputation: 6208

I'm fairly certain as long as you have an id attribute and runat="server", that you can access the tag by name and set Visible to true or false.

I did this with a table row (plain old <tr>) in one of my apps.

Edit - to clarify, I do mean "access the tag by name" in your code-behind.

Like, myHeader.Visible = true;

Upvotes: 4

Related Questions