asp.net中窗口相关操作总结(javascript)

1.打开新窗口
这个简单:Response.Write(@"<script
language=' javascript'>window.open('url');</script>");
2.关闭窗口
//关闭当前窗口,并提示用户时候关闭,yes关闭,no退出
Response.Write(@"<scriptlanguage=' javascript'>window.close();</script>");
//延迟关闭窗口(下面代码表示2秒后关闭,无需确认)
Response.Write(@"<script
language=' javascript'>setTimeout('self.close()',2000);</script>");
3.延迟时间
这个和上面的没有多少区别.我用到的情况是,在用户操作完毕给出提示,"n秒后,页面
转向"之类的只需去掉2重的Self.close()即可
Response.Write(@"<script
language=' javascript'>setTimeout('',2000);</script>");
4.弹出提示或警告窗口
Response.Write(@"<scriptlanguage=' javascript'>alert('添加成功,2秒钟后页面
将自动跳');</script>");
5.刷新其他页面
这个用到的情况还是不少.比如在B页面对数据更新和修改,另一页面A要保持最新数据
给客户,这是就要在对B操作完毕的情况下对A进行刷新:
Response.Write(@"<scriptlanguage=' javascript'>window.opener.location.
href='./default.aspx'</script>");
6.页面跳转
有时候在学要给出提示的情况下进行页面跳转,不能使用Response.Redirect("url");
比如,当客户操作完毕,单击按钮提交,弹出提示框(使用上面3和4),如果使用了
Response.Redirect("url");
那么页面将不给出提示,页就是3和4没有起作用就直接转向了.
如果你是下面的操作过程:
1).Response.Write(@"<scriptlanguage=' javascript'>alert('添加成功,2秒钟后页
面将自动跳');</script>");
2).Response.Write(@"<script
language=' javascript'>setTimeout('',2000);</script>");
3).页面转向:
Response.Write("<metahttp-equiv='refresh'
content='0;URL=./default.aspx'>");
//这个我不知道用 javascript怎么实现,熟悉的轻补充一下
7.窗口传制问题
这个问题比较烦,打开模态窗口(ShowModelDialog)我还没有实现,请各位补充.
具体情况是这样的,比如说A打开一个新窗口B,当用户对B操作完毕后,我们获得必要的
数据,自动将其赋给A中的TextBox等控件,这个过程是在客户端完成的.就像发送邮件时,
需要从地址本中选取,然后将选中的发送地址传回来.
1).在A中加入如下代码,打开一个新窗口B.
Response.Write(window.">@"window.
open('B.aspx','','toolbar=no,menubar=no,status=yes,location=no,
resizable=no,scrollbars=no,width=500,height=350');</script>");
2).对B操作完毕,获得必要数据tmpStr,然后将其赋值给A中的TextBox1
Response.Write(@"<script
language=' javascript'>opener.document.all.TextBox1. value
='"+tmpStr+"';</script>");
注意:这个过程是在客户单用 javascript完成的,因此我们不能按照服务端的编程习惯
以及不能使用web服务控件的服务端属性进行操作.TextBox1是一个web服务控件,
其id为TextBox1,A页面被服务器解析为html,通过浏览器浏览,TextBox1就变成了
纯html控件,我们这里用 javascript操作的也就是html控件,因此赋值使用的是
TextBox1的 value属性而不是Text属性.另外,web服务器控件的id被解析成html后,
id有时会变,我们只要注意使用服务器解析后的id就成了,在浏览器中右键->查看源文件
即可得到

对第七种操作情况最好使用打开模态窗口windows.ShowModelDialog(),但是比较麻烦,
我还没有实现.


接上:

调整本窗口大小和位置
Response.Write("<script>window.resizeTo(500,400);</script>");
Response.Write("<script>window.moveTo(300,200);</script>");


接上:

补:使用模态窗口传值

主要代码如下:
a.aspxanda.aspx.cs

<%@Pagelanguage="c#"Codebehind="a.aspx.cs"AutoEventWireup="false"
Inherits="Genesis02.a"%>
<HTML>
<HEAD>
<title>a</title>
<SCRIPTlanguage=" javascript">
varstr;

functionpop(url)

{
varmyDialog=document.a.TBoxType. value;

if(window.showModalDialog)
{
str=window.showModalDialog(url,myDialog,"dialogHeight:
300px;dialogWidth:500px;center:yes;help:no;resizable:yes;status:
no;");
if(typeof(str)!="undefined")
{
document.a.TBoxType. value=str;
}
}
}
</SCRIPT>
</HEAD>
<bodyMS_POSITIONING="GridLayout">
<formid="a"method="post"runat="server">
<asp:textboxid="TBoxType"
runat="server"></asp:textbox><asp:buttonid="BtnGetType"Runat="server"
Text="Open"></asp:button>
</form>
</body>
</HTML>
__________________________________________________________________

usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;

namespaceGenesis02
{
///<summary>
///a的摘要说明。
///</summary>
publicclassa:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.TextBoxTBoxType;
protectedSystem.Web.UI.WebControls.ButtonBtnGetType;

privatevoidPage_Load(objectsender,System.EventArgse)
{
if(!IsPostBack)

{
BtnGetType.Attributes[" onclick"]="pop('c.aspx');return
false;";
}
}

#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);

}
#endregion
}
}


#################################################################
b.aspxandb.aspx.cs

<%@Pagelanguage="c#"Codebehind="b.aspx.cs"AutoEventWireup="false"
Inherits="Genesis02.b"%>
<HTML>
<HEAD>
<title>b</title>
<SCRIPTlanguage=" javascript">
functioncloseme()
{

//top.return value=
window.document.all.LBoxRFAContent.options[window.document.all.LBoxRFAContent
.selectedindex]. value;
top.return value=document.getElementById("TBox value"). value;
top.close();
}

functionBody_Load()
{
if(window.dialogArguments!=null){
window.document.getElementById("TBox value"). value=
window.dialogArguments;
}
}
</SCRIPT>
</HEAD>
<bodyMS_POSITIONING="GridLayout"onload="Body_Load()">
<formid="b"method="post"runat="server">
<asp:Buttonid="BtnClose"style="Z-INDEX:101;LEFT:152px;
POSITION:absolute;TOP:131px"runat="server"Text="Closeme"></asp:Button>

<asp:TextBoxid="TBox value"style="Z-INDEX:102;LEFT:149px;
POSITION:absolute;TOP:69px"runat="server"></asp:TextBox>
</form>
</body>
</HTML>

__________________________________________________________________
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;

namespaceGenesis02
{
///<summary>
///b的摘要说明。
///</summary>
publicclassb:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.TextBoxTBox value;
protectedSystem.Web.UI.WebControls.ButtonBtnClose;


privatevoidPage_Load(objectsender,System.EventArgse)
{
if(!IsPostBack)
{
BtnClose.Attributes[" onclick"]="closeme();returnfalse;";
}
}

#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);

}
#endregion
}
}

#######################################################################

c.aspxandc.asp.cs

<%@Pagelanguage="c#"Codebehind="c.aspx.cs"AutoEventWireup="false"
Inherits="Genesis02.c"%>
<HTML>

<HEAD>
<TITLE>c</TITLE>
</HEAD>
<framesetrows="0,*">
<framesrc=" about:blank">
<framesrc="b.aspx">
</frameset>
</HTML>


____________________________________________________

usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;

namespaceGenesis02
{

///<summary>
///c的摘要说明。
///</summary>
publicclassc:System.Web.UI.Page
{
privatevoidPage_Load(objectsender,System.EventArgse)
{
//在此处放置用户代码以初始化页面
}

#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}

#############################################################################

c.aspxandc.asp.cs

<%@Pagelanguage="c#"Codebehind="c.aspx.cs"AutoEventWireup="false"
Inherits="Genesis02.c"%>
<HTML>
<HEAD>
<TITLE>c</TITLE>
</HEAD>
<framesetrows="0,*">
<framesrc=" about:blank">
<framesrc="b.aspx">
</frameset>
</HTML>


____________________________________________________

usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;

namespaceGenesis02
{
///<summary>
///c的摘要说明。
///</summary>
publicclassc:System.Web.UI.Page
{
privatevoidPage_Load(objectsender,System.EventArgse)
{
//在此处放置用户代码以初始化页面
}

#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:该调用是ASP.NETWeb窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///<summary>
///设计器支持所需的方法-不要使用代码编辑器修改
///此方法的内容。
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}


以上是使用模态窗口的所有主要代码

你可能感兴趣的:(JavaScript,.net,UI,asp.net,asp)