Client side show/hide div

On the page I have a div:

<div id="DivAddress" runat="server">
   some content here

I want the div to be hidden when the page loads, therefore at the end of the page I run:

<script type="text/javascript">
"#<%= this.DivAddress.ClientID %>").css({
"display": "none"

Below that div there are also buttons which hide or show that div by setting the display to none or block in a similar way (this example uses jquery, but I also used traditional ways).
all works fine, except that the state of the display property is not persisted between postbacks (it always appears visible after postback, as the script above runs only once - the page uses a master page with an UpdatePanel).
How do I persist the state between postbacks?

4/30/2009 2:12:24 PM 24353 articles. 2 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 2
Get it on Google Play
Get it on Apple App Store

try this script, if you have any control inside that div, you can also hide it.


if (document && document.getElementById)
var myControl = document.getElementById("myControl");
var myOtherControl = document.getElementById("myOtherControl");

if (myControl && myOtherControl)
{ = "visible"; = "relative"; = "hidden"; = "absolute";

4/30/2009 2:22:06 PM
Hello tsw_mik
In this scenario, you can use server-side HiddenField to maintain the state on client-side, please refer to the following tutorial:
[How Do I:] Use a Hidden Field to Store and Manipulate Client-Side Information


Lance Zhang
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
5/4/2009 7:59:54 AM

Hi tsw_mik,

You have to maintain display property of div by string it's current property in hidden html field. Please look at the following example.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="" >
<head runat="server">
    <title>Hide Show</title>
    <script type="text/javascript">
    function HideShow()
        if (document.getElementById('divHideShow').style.display == 'none')
            document.getElementById('divHideShow').style.display = ''
            document.getElementById('divHideShow').style.display = 'none'
        document.getElementById('hdnState').value = document.getElementById('divHideShow').style.display;
    <form id="form1" runat="server">
    <input type="hidden" runat="server" id="hdnState" value="" />
    <div id="divHideShow" runat="server">Hide Show</div>
    <a href="javascript:;" onclick="HideShow();">Test</a>

  Now at server side add this


    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        divHideShow.Style.Add("display", hdnState.Value)
    End Sub
Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
5/4/2009 12:27:42 PM

Similar Artilces:

List of client side function of extenders and controls for client side
Hello All,I am using AJAX control toolkit for my current project. Now I need to find out what client side functions I can call on an extender. Lets say I am using a PopControlExtender. Now I want to show the popup from a JS funtions.If I can do a guess then it would be something like this$find('ppce').show();From where I can find what client side functions I can call on those extensders. This is really a frusterating thing. I learn about extenders only from Learn tutorials, no help here and there. Can anybody please tell me where are documentations about all the extenders in the tool...

Jscript, moving from client-side to server-side (.NET)
Hey all I’m working translating a web-app written in client-side Jscript to run on the server-side as JScript.NET. Without needing to get too specific, I am using Jscript because the original page aggregated raw data to produce statistical results (this was done dynamically based on user 'sort-by' options). The final output is an html report that can be emailed. Because this is currently being done on the client side, as the raw data grows the load-time grows as well (to the point that has almost become unusable). I’m posting here to see if anyone has any experi...

Validation Controls in .NET ( Client side or server side?)
 i have a very basic question. We have all these validation controls in ( required field, range validator and others) question is the required field validator is a server side control. So does that mean that it does a post back? it client side or server side control  The only controls that post back are buttons and other inputs where you set AutoPostback="True", such as a dropdownlist or a textbox.  Another way of posting back is using an UpdatePanel and placing a trigger in it for a specified control and/or event. All controls are considered clien...

client side table rows not showing up server side?
so my code is something like... <updatepanel><submit button><updatepanel> <div><table><row><cell><Table id="mytable" runat="server"><thead><thead><tbody>...I create client side rows here</tbody>.....<div> so I add a bunch of rows client side...input some data... and then click submit.  However, when I look at the contents of Me.myTable on the server...I only see my 2 static header rows?  I've tried adding the runat attribute to the client side rows ....still didn't work.&nb...

Client Side Hide/Show with Validation
Here is my setup... <asp:RadioButtonList ID="rbl1" runat="server"> <asp:ListItem Text="Collect My Info" Value="0" /> <asp:ListItem Text="Skip This Step" Value="1" /></asp:RadioButtonList><asp:Panel ID="Info" runat="server"> <asp:TextBox ID="tb1" runat="server" /> <asp:RequiredFieldValidator ID="rfv1" runat="server" ControlToValidate="tb1" Text="Error :)" /></asp:Panel><asp:Panel ID="Skip" runat...

client side show and hide panel
I have several pages that I want to add some controlls that are normally not displayed. Say I have a datagrid and below the datagrid I add a panel. Just above the panel I have a link that executes some javascirpt to hide the span tag. In the panel I have a link that executes som js to hide the panel. All is working OK, but I want to have the panel hidden automatically when the page loads. I obviously can't use the visble propery of the panel since the html is never rendered to the client to be show. TIA, Craig p.s. my js is function HideAdminPanel() { if (document.getE...

Show/Hide Panel in Client Side
Hi. I have tow asp panels and tow html buttons to navigate between the this:document.getElementById('Panel1').style.display ='block'; document.getElementById('Panel2').style.display ='none';    the first button to show the first panel and hide the second panel . the second button had the opposite purpose. inside the panels there is asp controsl. every thing work good until I use postback  by any control in the panels,for example when I click an asp button in the panel evry panel return to the defaut style. I put this...

Showing and hiding Panels on the client side?
hello, I have a couple of panels I am useing on a page to mimic a tab based navigation menu. I have been able to use linkbutton clicks to show and hide panels to simulate the tabs. Is it possible to do this on the client side rather than making trips back to the server? Is this similar to the UI validation controls that can validate input from either the client or server side, or would I have to write the script myself to accomplish this? Thanks, jigster... an asp:panel is just a <div> tag on the client-side. using view->source would have told you this.RTFM - straight ...

When to use client side varidation and server side varidation in .net?
In .net or classic web application we can varidate user data either on client isde or server side. How to select which side varidate to be used? Thanks! Generally, I use both client and server validation. I make sure the input is in the correct format and reasonably valid on the client, then I verify the data on the server. The extent of validation also depends on the type of data that I need to validate.Here are a few references:Validating ASP.NET Server ControlsIntroduction to Validating User Input in Web FormsClient-Side Validation for ASP.NET Server ControlsSecurity Checklist...

Is it possible to call client side function from server side code without initial client request?
Atlas is great. I'm using timer to periodically check database changes on server to populate client side controls with new data. Is it possible to do it without a lot of client requests to server which takes a huge useless network traffic? Server should call client side function on all connected clients when, for example, 'database updated' event occurs on server. Thanks. Hi~ Just for your interest, I think you could have a look at Comet, many web IM like Gmail's embeded Gtalk and are built on this architecture你好! Just FYI o_O...

client-side and server-side?
hi, can someone tells me how diff is client side and server side are these two? When I tried to do validation ... I would use Javascript ... which has something like: document.forms[0] ... I think that's client side. My understanding on server side is the "form" ... like u will have <form action=".." method=post> ..... </form> ... so it will send to server ... am I on the right track? Are there any other type of server side examples? Hi, ASP.NET itself is server side. Every piece of code processed is done on a server. What comes out of this is sent ...

Client side and server side
We have a application, where we have some validation on the clientside using EnableClientSideValidation. If you don't have fullscreen you can't see some of the error-messages. What we want is to jump to the place on the page where the message is displayed. One problem is that the button is a serverbutton (runat="server"). How can we accomplish this on the clientside using the same button. I have tried to use "onClientClick" and a link something like this:   <A HREF=>form<...

Server-side or Client-side
In general, I'm wondering if there are any criteria to use when choosing between using a client side element or a server side element. For example, if I'm going to put an HTML table on a page, how do I decide whether or not to use a server control?  Should the server side always be chosen or if there is not explicit server side functionality required is it better to opt for a "normal" client side table? Obviously, if there is a need for server side control the question is answered, I'm looking more at more ambiguous situations. Thanks  This is from Micros...

Server Side or Client Side
Hi I'm a bit confused about this whole server side / client side thing. Are applets, embeded objects consider client side? If I have a form within my aspx page which connects to a database on the server side what is it considered? If I have some business logic written within a VB file when the client access the functions within that business logic (for example some kind of validation function) does the client browser actually downloads that VB file? Can someone suggest how to differentiate between client side and server side components within a based website?  Hi, i can&#...

Web resources about - Client side show/hide div -

MUD client - Wikipedia, the free encyclopedia
A MUD client is a computer application used to connect to a MUD , a type of multiplayer online game . Generally, a MUD client is a very basic ...

3Q Digital Offers Peek At 3Q Facebook Ad Performance By Its Largest Clients
With Facebook set to report its third-quarter earnings Wednesday , digital marketing agency 3Q Digital offered some insight on how the social ...

Gallop Labs hires former Facebook Client Partner as Director of Sales
Gallop Labs , a social marketing and analytics firm, announced that it has hired former Facebook Client Partner Andrew Peebles as the company’s ...

Lawyer labels client 'stupid' after New Year text to ex lands him behind bars for a week
Man's five days in prison for New Year text was significant &quot;wake-up call&quot;, lawyer says.

Canberra psychology clinic accidentally reveals clients' personal details in email
A Canberra psychology clinic has apologised after it accidentally shared personal details of hundreds of patients in a group email.

Never Complain To Clients Or Adversaries
Even trial lawyers that learn and have fun all the time deal with frustrations and have their gripes. But we should never share those gripes ...

Anchorage Assembly candidate drops out rather than reveal tutoring clients
... Anchorage Budget Advisory Commission, has withdrawn a bid for the Assembly because she did not want to list the names and addresses of clients ...

Spotlight On NW Creative: Fell Swoop And Its Unique Client Mix
After living in Seattle for a few years, it’s become clear to me that many shops here struggle to capture significant business from clients headquartered ...

New online FX broker group rails against client money laws
A group of online broking firms have launched a desperate bid to sway the government on its proposed client fund segregation laws.

SanDisk Announces X400 Client SSD for OEMs
... Like the X300, the X400 uses TLC NAND flash and relies on SLC-mode write caching to provide competitive write speeds. SanDisk OEM Client SSD ...

Resources last updated: 1/16/2016 3:56:39 PM