当前位置:编程学习 > C#/ASP.NET >>

关于一个弹出层的问题

页面中点Button1按钮,弹出隐藏层,隐藏层里面有TextBox和Button2,Button2通过单击事件将TextBox里面的值传到数据库中,但点了Button2以后,整个页面刷新,隐藏层也随着页面的刷新而再次隐藏起来,如要显示,得重新点Button1来显示,当然这不是我要的效果。
我要的效果是:当我点Button2按钮的时候,页面刷新后,隐藏层处于显示状态?
请问,可以达到我要的效果吗?具体怎么做,谢谢各位大神,请帮帮我!

请不要让我用AJAX和Iframe.因为这不适合我。
我一定要页面刷新,然后隐藏层仍然处理显示状态。 
--------------------编程问答-------------------- 你的问题,我觉得可以在弹出层中放一个Updatepanel
可以:
一、将TextBox和Button2放在UpdatePanel中,并设置UpdatePanel的触发控件为Button2
    这样你点击Button就不会整页刷新。
二、干脆就弹模态窗口吧,省事。
个人观点,仅供参考。 --------------------编程问答-------------------- Page_Load里判断是不是需要显示。

判断不要放在!IsPostBack里 --------------------编程问答--------------------

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>弹出层并可拖拽</title>
<style>
html,body{height:100%;overflow:hidden;}
body,div,h2{margin:0;padding:0;}
body{font:12px/1.5 Tahoma;}
center{padding-top:10px;}
button{cursor:pointer;}
#overlay{position:absolute;top:0;left:0;width:100%;height:100%;background:#000;opacity:0.5;filter:alpha(opacity=50);display:none;}
#win{position:absolute;top:50%;left:50%;width:400px;height:200px;background:#fff;border:4px solid #f90;margin:-102px 0 0 -202px;display:none;}
h2{font-size:12px;height:18px;text-align:right;background:#FC0;border-bottom:3px solid #f90;padding:5px;cursor:move;}
h2 span{color:#f90;cursor:pointer;background:#fff;border:1px solid #f90;padding:0 2px;}
</style>
<script>
window.onload = function ()
{
var oWin = document.getElementById("win");
var oLay = document.getElementById("overlay");
var oBtn = document.getElementsByTagName("button")[0];
var oClose = document.getElementById("close");
var oH2 = oWin.getElementsByTagName("h2")[0];
var bDrag = false;
var disX = disY = 0;
oBtn.onclick = function ()
{
oLay.style.display = "block";
oWin.style.display = "block"
};
oClose.onclick = function ()
{
oLay.style.display = "none";
oWin.style.display = "none"
};
oClose.onmousedown = function (event)
{
(event || window.event).cancelBubble = true;
};
oH2.onmousedown = function (event)
{
var event = event || window.event;
bDrag = true;
disX = event.clientX - oWin.offsetLeft;
disY = event.clientY - oWin.offsetTop;
this.setCapture && this.setCapture();
return false
};
document.onmousemove = function (event)
{
if (!bDrag) return;
var event = event || window.event;
var iL = event.clientX - disX;
var iT = event.clientY - disY;
var maxL = document.documentElement.clientWidth - oWin.offsetWidth;
var maxT = document.documentElement.clientHeight - oWin.offsetHeight;
iL = iL < 0 ? 0 : iL;
iL = iL > maxL ? maxL : iL;
iT = iT < 0 ? 0 : iT;
iT = iT > maxT ? maxT : iT;
oWin.style.marginTop = oWin.style.marginLeft = 0;
oWin.style.left = iL + "px";
oWin.style.top = iT + "px";
return false
};
document.onmouseup = window.onblur = oH2.onlosecapture = function ()
{
bDrag = false;
oH2.releaseCapture && oH2.releaseCapture();
};
};
</script>
</head>
<body>
<div id="overlay"></div>
<div id="win"><h2><span id="close">×</span></h2>内容</div>
<center><button>弹出层</button></center>
</body>
</html><br />如不能显示效果,请按Ctrl+F5刷新本页
--------------------编程问答-------------------- 楼主。在你的单机时间里面加上
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "JS", "document.getElementByID('隐藏层的ID').style.display='block';", true); --------------------编程问答--------------------

  /// <summary>
        /// 获取将弹出页面放在弹出DIV中显示的脚本
        /// </summary>
        /// <param name="page"></param>
        /// <param name="title">弹出页面的标题</param>
        /// <param name="url">要弹出的url</param>
        /// <param name="width">弹出DIV的宽,若无,则传入""</param>
        /// <param name="height">弹出DIV的高,若无,则传入""</param>
        /// <param name="callback">关闭弹出框后的回调函数 其中回调函数包含弹出框页面的window.arguments</param>
        public static string OpenDialog(string title, string url, string width, string height, string callback)
        {
            if (string.IsNullOrEmpty(callback)) callback = "null";
            string script = string.Format("openDialog('{0}','{1}','{2}','{3}',{4});return false;", title, url, width, height, callback);
            return script;
        }

--后台调用
btnView.OnClientClick = jsBuilder.OpenDialog("查看个人详细信息", sbUrl.ToString(), "800", "550",'此处可以使用回调函数') + "return false;";


LZ可以自己把弹出层封装一下,使用起来就方便多了,可以支持无限弹层,要刷新的话在你弹层的父页面放一个隐藏的刷新按钮,然后在关闭弹出层的时候使用回调函数,调用一下刷新按钮的事件不就OK了,刷新按钮里面可以写你想写的任何代码。仅提供点思路,供参考。 --------------------编程问答-------------------- 在Page_Load事件里添加
   Page.ClientScript.RegisterStartupScript(GetType(), "open", "<script>$('#你的DIVID').show()</script>");

当然你得有个判断不然第一次打开页面DIV也显示出来了,可以用ViewState判断,当点击Button2的时候给ViewState赋值 --------------------编程问答--------------------

这样的直接在前台js控制就行

不用管后台的 什么 Ispostback --------------------编程问答-------------------- 在button事件里面 添加完数据到数据库以后 直接跳转到本页面 加个参数标志?x=0, 然后在后台 page_load里面判断 =0则 显示div =1则隐藏 --------------------编程问答--------------------    用jquery的动态绑定事件啊、
   你可以用最开始弹出DIV的那个按钮的ID 绑定它下面的DIV的下面的按钮的Onlick事件啊、
   这样,你就可以实现你所需要的传递数据了啊。
    
    $("#button1>div>button").live("click", function() {});

   希望对你有用。

--------------------编程问答-------------------- 用jquery的动态绑定事件:
$("#button1>div>button").live("click", function() {});
就是你的按钮下面的DIV下面的那个按钮的click事件。
你可以写在你的button1的click事件中。这样应该是可以实现你想要的结果的。
希望对你有用吧。
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,