Click here to Skip to main content
15,844,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a popup div to which i am showing that from server side. I want to hiding that popup from client side. Any suggestion please feel free to share.
My code is given below:-

design page
------------------------
ASP.NET
<div id="Popupdiv"  runat="server" class="popupwindow" visible="false"> 
<img alt="" src="../images/close.png"  önclick="f1();" /> 

javascript
--------------------------
JavaScript
function f1() 
{ 
div1 = document.getElementById('<%=Popupdiv.ClientID%>') 
div1.style.visibility="hidden"; 
} 

code behind
------------------------------------------
C#
Popupdiv.Visible = true; 

It works fine but measure problem is for every post back that popup div displying automatically.
Posted
Updated 20-Jul-12 9:54am
v2

It works fine but measure problem is for every post back that popup div displying automatically.
I believe this is your issue that you are talking of.

Now, two things.
1. You should use display style attribute instead of visibility attribute. Display will hide/show keeping the control on the page. Setting, visible property does not render the control at all which makes it impossible to access on client side.

2. Your div display is reset on postback as the state is not maintained automatically here. You changed the display of it client side which server is not aware of. To persist the set property on postback, you need to track the change made and set it again on server side. One of the ways to do it:
a. Keep a hidden field on your page. (make it server control if using input of hidden type) (Default it to true - which means show div)
b. Use this hidden field as a flag - true/false: true for display, false for hide
c. When you are hiding the div from client side (code f1() above), set the hidden field too. Set 'false' when hiding the div.
d. During postback, in your page_load, check the value of hidden field. Based on the value of hidden field, set the display attribute of div.
Something like:
C#
if(hdnField.Value == "false")
  Popupdiv.Attributes.Add("style", "display:none");


Try!

[SNS] Code updated.
 
Share this answer
 
v2
Comments
Shemeer NS 20-Jul-12 15:27pm    
you made it more clear... 5'ed
If u want to hide from clientSide then you should set attribute style display:none from code behind instead of Visible Property

Once you set the display attribute from codebehind then just change it to block from client side
 
Share this answer
 
Comments
Sandeep Mewara 20-Jul-12 14:54pm    
Comment from OP:
How to set attribute for display:none ? Kindly mention one example.

I have gone though your suggestion but same thing is going on. The popup div hides but then for every post back that popup coming automatically.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900