View Full Version : Show <div> on postback

07-22-2011, 04:51 PM
I'm sure I have pretty simple question but for some reasons I can't find answer

I have a basic JS function to show an element

function show(obj1) {
var div = document.getElementById(obj1);
div.style.display = 'inline';

<a onclick="show('Div')>Show Panel</a>

<div id="Div" runat="server" style="display: none">
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />

Displaying the panel is not a problem but how do I keep it shown on a postback (btnSearch_click)?

protected void btnSearch_Click(object sender, EventArgs e)
//Do something
Div.Attributes.Add("display", "inline'");
//and Div.Style("display") = "inline";
//and Div.Visible = true;

no matter what I do, it gets hidden.

08-06-2011, 08:02 PM
have you tried this :

Div.Visible = Page.IsPostBack

08-07-2011, 02:39 AM
i have only ever run into problems with setting runat="server" to my divs.. usually i loose all my CSS attributes... My soltion (and what seems to be "better practice") is "wrapping" the div in question in a panel and showing/hiding the panel on postback... this works better (imo)...