Click here to Skip to main content
15,897,718 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
For an HTML element , I can dynamically hide it by
C#
sourceDoc1.Attributes["style"] = "display: none";

After it is hidden, but I can't turn it to displayed by
C#
sourceDoc1.Attributes["style"] = "display: block";

What's wrong in my 'turn-on' code? Thanks.

What I have tried:

Code-behind: Dynamically display / hide a HTML element
Posted
Updated 29-Apr-16 7:19am

1 solution

Try:
C#
sourceDoc1.Style["display"] = "none";

and:
C#
sourceDoc1.Style["display"] = "block";


If that doesn't work, you'll need to examine the rendered HTML, and use the browser's developer tools to inspect the element to see why it's not visible.
 
Share this answer
 
Comments
s yu 29-Apr-16 13:39pm    
RD: Thanks for your response. I tried but the results are the same. I also tried
sourceDoc1.Attributes.CssStyle.Value = "display:block";
and
sourceDoc1.Attributes.CssStyle.Value = "display:block; visibility:visible";
the results are the same even though its value is correct though the debugging.
Don't know why. Thanks anyway.
Richard Deeming 29-Apr-16 13:45pm    
So as I said, look at the generated HTML, and use your browser's developer tools to inspect the element.
s yu 29-Apr-16 14:14pm    
You are right. I added sourceDoc1.Visible = true; then the problem is solved. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900