...

View Full Version : Show <div> on postback



esb01
07-22-2011, 03: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">
<table><tr><td>
...Controls
</td></tr>
<tr><td>
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</td></tr>
</table>
</div>

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
//tried
Div.Attributes.Add("display", "inline'");
//and Div.Style("display") = "inline";
//and Div.Visible = true;
}

no matter what I do, it gets hidden.

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


Div.Visible = Page.IsPostBack

alykins
08-07-2011, 01: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)...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum