从服务器端和客户端弹出显示和隐藏 [英] Popup show and hide from both server side and client side

查看:96
本文介绍了从服务器端和客户端弹出显示和隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出div,我正在从服务器端向其显示.我想从客户端隐藏该弹出窗口.任何建议,请随时分享.
我的代码如下:-

设计页面
------------------------

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
------------------------

<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
------------------------------------------

Popupdiv.Visible = true; 


效果很好,但是度量问题是针对弹出div自动显示的每个帖子.


It works fine but measure problem is for every post back that popup div displying automatically.

推荐答案

效果很好,但度量问题是针对弹出菜单的每个帖子div自动显示.
我相信这是您正在谈论的问题.

现在,有两件事.
1.您应该使用display style属性代替可见性属性.显示将隐藏/显示,使控件保持在页面上.设置可见属性完全不会呈现控件,这使得无法在客户端进行访问.

2.您的div显示在回发时被重置,因为此处的状态不会自动保持.您更改了服务器不知道的客户端的显示.要将set属性保留在回发中,您需要跟踪所做的更改,然后在服务器端再次进行设置.方法之一:
一个.在页面上保留hidden field. (如果使用隐藏类型的输入,则使其成为服务器控件)(默认为true-表示显示div)
b.使用此隐藏字段作为标志-true/false:对于显示为true,对于hide为false
C.从客户端隐藏div时(上面的代码f1()),也请设置隐藏字段.隐藏div时将其设置为"false".
d.回发期间,在page_load中,检查hidden字段的值.根据隐藏字段的值,设置div的显示属性.
像这样的东西:
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:
if(hdnField.Value == "false")
  Popupdiv.Attributes.Add("style", "display:none");



试试吧!

[SNS]代码已更新.



Try!

[SNS] Code updated.


如果您想从clientSide隐藏,则应从代码后面设置属性style display:none而不是Visible Property

从代码后面设置display 属性后,只需从客户端将其更改为block
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


这篇关于从服务器端和客户端弹出显示和隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆