开发者

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_Clic开发者_如何学运维k" 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


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.


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜