Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
Control myControl1 = FindControl("btn1");
                if (myControl1 != null)
                {
                    myControl1.Visible = true;


                }

                Control myControl2 = FindControl("btn2");
                if (myControl2 != null)
                {
                    myControl2.Visible = true;
                }

In my page load i have this two that i display two controls.
onclick in aspx page i have this

JavaScript
window.onload = function (e) {
        document.getElementById("btn1").style.visibility = "hidden";
        document.getElementById("btn2").style.visibility = "hidden";
    };

I have this code here because i dont wont to display them on client side only on server side
but hiding them in server side click event on a hrefs is not firingen?



JavaScript
function ShowItems() {


            document.getElementById("btn1").style.visibility="display";
            document.getElementById("btn2").style.visibility="none";

        }


    function DontDisplayItems()
    {

        document.getElementById("btn1")style.visibility="none";
        document.getElementById("btn2").style.visibility="display";

    }



ASP.NET
<div id="btn1" style="float:right;"  runat="server">
         <a href="#"  >Button 1</a>


    </div>
    <div id="btn2" style="float:right;"  runat="server">
         <a href="#"   >Button 2</a>


    </div>


The problem is that my button wont be display:
Posted
Updated 23-Mar-15 4:13am
v2

1 solution

When you hide something in C# by setting .Visible = false then the control is not in the html at all that is sent to the client. Therefore you cannot change it's visibility in JavaScript.

To do so, don't use the .Visible property but instead use display or visibility properties in JavaScript only.
 
Share this answer
 
Comments
sudevsu 23-Mar-15 10:17am    
5
Kurac1 23-Mar-15 10:28am    
What do u mean?
Sergey Alexandrovich Kryukov 23-Mar-15 10:44am    
It means that you still need to grasp the general idea on how Web works, ASP.NET in particular.
You need to understand what server part does and what client part does.
—SA
ZurdoDev 23-Mar-15 10:55am    
I thought the user was just asking what sudevsu meant by just posting "5". Not sure though.
Sergey Alexandrovich Kryukov 23-Mar-15 10:58am    
Ha-ha, maybe... :-) but I think that my idea to learn what Web actually does should be applicable anyway. :-)
—SA

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