Default.aspx如何获取模式对话框Default2.aspx中Textbox的值,例如:
Default.aspx是一个数据表,点击添加按钮弹出一个模式对话框Default2.aspx,然后后输入数据点击保存关闭Default2.aspx,之后再刷新Default.aspx的数据表。
要求:不能用Default2.aspx写入数据到数据库的方法,需要页面间传值。参考代码:<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function mody()
{
//下面是打开模态对话框
var sDate=window.showModalDialog("Default2.aspx","ok","center=1;dialogHeight=17.5;dialogWidth=50;help=0;status=0;resizable=1");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="确定" OnClientClick="mody()" />
</div>
</form>
</body>
</html>
Default.aspx是一个数据表,点击添加按钮弹出一个模式对话框Default2.aspx,然后后输入数据点击保存关闭Default2.aspx,之后再刷新Default.aspx的数据表。
要求:不能用Default2.aspx写入数据到数据库的方法,需要页面间传值。参考代码:<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function mody()
{
//下面是打开模态对话框
var sDate=window.showModalDialog("Default2.aspx","ok","center=1;dialogHeight=17.5;dialogWidth=50;help=0;status=0;resizable=1");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="确定" OnClientClick="mody()" />
</div>
</form>
</body>
</html>
解决方案 »
- 无法获得数据的问题
- datalist中itemtemplate问题!达人速度了!拿分好机会啊!
- 做一个简单的网站,读取ACCESS中数据,只是读取
- 大家进来看看,这样的功能能实现吗?
- 为什么生成DLL以后不能注册?
- 关于DataGrid分页的一个问题,请大侠帮帮忙……
- 下面是陕北吴旗娃用SQL SERVER写的分页的存储过程,哪位有在ORACLE数据库上应用的实例,帮我将下面的存储过程改成ORACLE的存储过程。
- 简单的老问题,asp.net中的messagebox
- 祝贺[中国WEB开发者网络]开通,接分!
- 有没有将汉字转化为语音的控件或组件或dll?
- 上传文件的按钮怎么写
- C#后台调用Alert方法发现的一个奇怪的问题!
parent.htm
<script>
var obj = new Object();
obj.name="51js";
window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");
</script>
modal.htm
<script>
var obj = window.dialogArguments
alert("您传递的参数为:" + obj.name)
</script>
-------------------------------
2. 可以通过window.returnValue向打开对话框的窗口返回信息,当然也可以是对象。例如:
------------------------------
parent.htm
<script>
str =window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");
alert(str);
</script>
modal.htm
<script>
window.returnValue="http://homepage.yesky.com";
</script>
<script language="javascript" type="text/javascript">
function Select()
{
var arr=showModalDialog('Search.aspx','','width=480,height=380,left=250,top=250');
document.getElementById(txtID).value=arr;
}
</script>
Search.aspx.cs /// <summary>
/// 用StringBuilder类实现用C#服务器控件写前端控制程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
StringBuilder s = new StringBuilder();
s.Append(" <script language=javascript>" + "\n");
s.Append("var a='" + this.GetSelectValue() + "';" + "\n");
s.Append("window.returnValue=a" + "\n");
s.Append("window.close();" + "\n");
s.Append(" </script>");
Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;
string csname = "ltype";
if (!cs.IsStartupScriptRegistered(cstype, csname))
cs.RegisterStartupScript(cstype, csname, s.ToString());
}
/// <summary>
/// 返回TextBox1中的值
/// </summary>
/// <returns></returns>
protected string GetSelectValue()
{
string rvalue = "";
if (TextBox1.Text != null)
{
rvalue = TextBox1.Text; //返回名称
}
return rvalue;
}
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<mce:script type="text/javascript"><!--
function oper()
{
var address=window.showModalDialog("return.html","aaaa","dialogWidth=400px;dialogHeight=200px");
document.myform.txtReturnValue.value=address;
}
// --></mce:script>
</head>
<body>
<form name="myform" method="post">
<div>
<div><input type="button" name="xxx" value="返回值" onclick="oper()" /><input type="text" name="txtReturnValue" /></div>
</div>
</form>
</body>
</html>
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhoukang0916/archive/2009/10/28/4735825.aspx<html>
<head>
<Title></Title>
<mce:script type="text/javascript"><!--
function returntest()
{
window.returnValue="我是返回值";
window.close();
}
// --></mce:script>
</head>
<body>
<form>
<input type="button" onClick="returntest()" value="返回值"/>
</form>
<body>
<html> 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zhoukang0916/archive/2009/10/28/4735825.aspx
http://blog.csdn.net/zhoukang0916/archive/2009/10/28/4735825.aspx
{
Response.Write("<script language:javascript>javascript:closewin();</script>");
}会弹出一个新Default2.aspx,再点击Button1才会关闭。如果是这样就能立即关闭。
<input type="button" value="确定" onclick="return closewin()" />
<asp:Button ID="Button2" runat="server" Text="Button" OnClientClick="return closewin()" />这样能关闭,但关闭后又自己弹出了一个有地址栏的Default2.aspx,难道非要用客户端控件不可?假如要处理一些数据再返回怎么办?现在我知道怎么返回数据了(不是服务端的)。
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function mody()
{
//下面是打开模态对话框
var str=window.showModalDialog("Default2.aspx","","center=1;dialogHeight=17.5;dialogWidth=50;help=0;status=0;resizable=1");
document.getElementById('TextBox1').value=str[0];
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" CssClass="txt"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="确定" OnClientClick="mody()" />
</div>
</form>
</body>
</html>
Default2.aspx<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function closewin()
{
var tex=document.getElementById('TextBox1').value;
var my_array = new Array(tex);
window.returnValue = my_array;
window.close();
return false;//如果用服务器端按钮需要这句,不知道为什么
}
</script>
</head>
<body onunload="javascript:closewin()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input type="button" value="确定" onclick="closewin()" />
<asp:Button ID="Button2" runat="server" Text="确定(服务端)" OnClientClick="return closewin()" /></div>
</form>
</body>
</html>
说明:
Default2.aspx中Button2的OnClientClick="return closewin()" 如果没有return会弹出新页面,目前尚不知道原因。如果Button2写了服务端代码,也会出现新页面,也就是无法在后台处理数据后再返回。如果真要对数据进行处理,要用JS或者Post到第三个页面来处理,然后再Response回来接受。
Default.aspx页可以通过document.getElementById('TextBox1').value=str[0]来获取返回值,这时已经可以在page_load里面获取textbox1改变的值了(因为Default2.aspx关闭时居然刷新了Default.aspx),至于服务端获取客户端控件值,目前只知道textbox和HiddenField可以在后台获取,其余似乎不行,vs2003下只能用textbox。
Default2.aspx中<body onunload="javascript:closewin()">是用于直接点X关闭窗体时发生的。