开发者

Keep div visible on postback

I have a div which开发者_C百科 needs to be hidden when the page first loads. If the user then clicks the "btnShowDiv" button, it should then become visible.

The problem I have is that, once it has become visible I need it to stay visible. At the moment, whenever I click on an asp button the div reloads and becomes hidden again.

<DIV id="myDiv" style="display:none;">
   <label>some text</label>
</DIV>

<input type=button id="btnShowDiv" onClick="document.getElementById('myDiv').style.display='block';"> 

<asp:button id="btnASPButton"></asp:button>


Because asp button click causes the Postback to server, and reloading the page again. So the div goes back to initial state.

have a hidden field indicator like isDivVisible and turn it to 1 on first visibling the div.

and check this state on form load again to set the div visible.


You could use an asp:panel (renders as a div) instead of a div and handle the Visible property in your click handler.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜