sandeep
sandeep

Reputation: 25

Div is hidden but again showed up

I have a situation where I have no of Divs on my page , based upon the autorization I want to hide show the data in those Divs , Problem is Divs are not Hidden ,this is my client script code.

function ShowDiv(obj, condition) {
    var dataDiv = document.getElementById(obj);
    //alert(obj);
    if (condition == true) {
        dataDiv.style.display = "none";
    }
    else {
        dataDiv.style.display = "block";
    }
}

this is a sample code, when I call this code on button click

<asp:Button ID="Button1" runat="server" onclick="Button1_Click" OnClientClick="ShowDiv('Div1','True');" Text="Button" />

by this code it does hide the div but gain displays it on postback. also can I hide no of Div on one go. i.e now I'm using getelementbyid is there any grouping alowed in HTML.

Thanks

Upvotes: 0

Views: 82

Answers (2)

Michael Christensen
Michael Christensen

Reputation: 1786

If its based on authorization you should do it on server side only. Add runat="server" to make the divs html server controls. Also give them ID. Then in your code behind check for authorization and set the hidden property accordingly.

Upvotes: 2

aikixd
aikixd

Reputation: 514

you pass a string to the function, but "True" != true. you have to send a boolean like so:

OnClientClick="ShowDiv('Div1',true);"

Upvotes: 0

Related Questions