弹出对话框关闭时返回值wj-wangjun
弹出对话框关闭时返回值 1.
//----------ImportListADD.aspx文件
//----脚本
<script type="text/javascript" language="javascript">
function IBtnSearch()
{
var arg=window.showModalDialog("ShowDialog.aspx");
if(arg!=null)
{
this.form1.aBox.value=arg[0];
}
}
</script>
<input id="aBox" type="text" runat="server" /> //这个地方一定要加runat="server" 要不然会一闪而过的.也就是无法在客客户端页面显示传回的数据.
<input type="image" id="IBtnSearch" src= "../pictures/button_PIC/search2.bmp" onclick="IBtnSearch()"/>
//--------ShowDialog.aspx文件
<title>无标题页</title>
<base target="_self"/>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
<asp:TextBox ID="tt" runat="server"></asp:TextBox>
</form>
</body>
</html>
//-------ShowDialog.aspx.cs文件
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>var arr=new Array(); arr[0]='" + tt.Text.ToString()+ "'; window.returnValue=arr;alert(arr[0]);window.close();</script>");
}
//----脚本
<script type="text/javascript" language="javascript">
function IBtnSearch()
{
var arg=window.showModalDialog("ShowDialog.aspx");
if(arg!=null)
{
this.form1.aBox.value=arg[0];
}
}
</script>
<input id="aBox" type="text" runat="server" /> //这个地方一定要加runat="server" 要不然会一闪而过的.也就是无法在客客户端页面显示传回的数据.
<input type="image" id="IBtnSearch" src= "../pictures/button_PIC/search2.bmp" onclick="IBtnSearch()"/>
//--------ShowDialog.aspx文件
<title>无标题页</title>
<base target="_self"/>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
<asp:TextBox ID="tt" runat="server"></asp:TextBox>
</form>
</body>
</html>
//-------ShowDialog.aspx.cs文件
protected void Button1_Click1(object sender, EventArgs e)
{
Response.Write("<script language='javascript'>var arr=new Array(); arr[0]='" + tt.Text.ToString()+ "'; window.returnValue=arr;alert(arr[0]);window.close();</script>");
}
或者
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" CausesValidation="false" Text="Button" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" CausesValidation="false" Text="Button" />
protected void Button1_Click(object sender, EventArgs e)
{//string aa = "TextBox1";
string strScript = "<script language='javascript'>";
strScript += "var arg=window.showModalDialog('ShowDialog.aspx?tableName=abcd&lblName=xxx','','dialogHeight:45;dialogWidth:55;center:1;scroll:on ;resizable:yes');";
strScript += "if(arg!=null){";
strScript += "form1.elements['TextBox1'].value = arg[0];}";
//或者 strScript += "form1.elements['"+aa+"'].value = arg[0];}";
strScript += "</script>";
if (!Page.IsStartupScriptRegistered("scriptName"))
Page.RegisterStartupScript("scriptName", strScript);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptName", strScript);
}
{//string aa = "TextBox1";
string strScript = "<script language='javascript'>";
strScript += "var arg=window.showModalDialog('ShowDialog.aspx?tableName=abcd&lblName=xxx','','dialogHeight:45;dialogWidth:55;center:1;scroll:on ;resizable:yes');";
strScript += "if(arg!=null){";
strScript += "form1.elements['TextBox1'].value = arg[0];}";
//或者 strScript += "form1.elements['"+aa+"'].value = arg[0];}";
strScript += "</script>";
if (!Page.IsStartupScriptRegistered("scriptName"))
Page.RegisterStartupScript("scriptName", strScript);
//Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptName", strScript);
}
弹出对话框关闭时返回值 2.
//-------------Unit.aspx 文件
<asp:TextBox ID="txtCurNo" runat="server" MaxLength="10" AutoPostBack="True" OnTextChanged="txtCurNo_TextChanged"></asp:TextBox>
<asp:TextBox ID="txtCurName" runat="server" MaxLength="10" AutoPostBack="True" Width="428px"></asp:TextBox>
//--点这个铵扭
<asp:Button ID="butOpen" runat="server" Text="打开" OnClick="butOpen_Click" CausesValidation="False" Width="78px" />
//-------------Unit.aspx.cs 文件
protected void butOpen_Click(object sender, EventArgs e)
{
DAL.CommDAL.ShowComBox(this, 32, 25, "form1", "txtCurNo", "txtCurName", "OnQueryCode", "Unit", "单位编号");
}
//this 由于public partial class Unit : System.Web.UI.Page 所以这个this指的是System.Web.UI.Page
//form1 指的是:<body> <form id="form1" runat="server" >
//"txtCurNo", "txtCurName", 是指文本框的ID值
//"OnQueryCode" 是指脚本的名字
//Unit 是指: 文件名
//"单位编号" 是指:文本框的标签.
//-----------CommDAL.cs 文件
public static void ShowComBox(System.Web.UI.Page page, int height, int width, string formName, string txtCode, string txtName, string scriptName, string tableName, string lblName)
{
string scriptString = "<script language=javascript>";
scriptString += "var arg = window.showModalDialog( '../SystemFrameWorks/CommonQuery.aspx?tableName=" + tableName + "&lblName=" + lblName + "&ts='+Date() ,'','dialogHeight:45;dialogWidth:55;center:1;scroll:on ;resizable:yes');";
scriptString += "if (arg != null) { ";
scriptString += "if (" + formName + ".elements['" + txtCode + "']!=null){" + formName + ".elements['" + txtCode + "'].value = arg[0];} ";
scriptString += "if (" + formName + ".elements['" + txtName + "']!=null){" + formName + ".elements['" + txtName + "'].value = arg[1];} ";
scriptString += "if (" + formName + ".elements['butLoadData']!=null){" + formName + ".elements['butLoadData'].click();}} ";
scriptString += "</script>";
if (!page.IsStartupScriptRegistered(scriptName))
page.RegisterStartupScript(scriptName, scriptString);
}
//--------------CommonQuery.aspx 文件
<asp:TemplateField HeaderText="选 择">
<ItemStyle Width="60px" Height="30px" />
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl="../images/choose.gif" ID="delid" CommandName="del" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
//-------CommonQuery.aspx 文件----------------点击按钮后返回对话框中的值.
protected void gridData_RowCommand(object sender, GridViewCommandEventArgs e)
{
ImageButton lb = (ImageButton)e.CommandSource;
GridViewRow curgvr = (GridViewRow)lb.Parent.Parent;
string aa = curgvr.Cells[1].Text.ToString();
string aaa = curgvr.Cells[2].Text.ToString();
string tableName = Request.QueryString["tableName"].Trim();
string output = "<script>var arr=new Array(); arr[0]='" + aa + "'; arr[1]='" + aaa +
"'; window.returnValue = arr;" + " window.close(); </script>";
output = output.Replace(" ", "");
Response.Write(output);
<asp:TextBox ID="txtCurNo" runat="server" MaxLength="10" AutoPostBack="True" OnTextChanged="txtCurNo_TextChanged"></asp:TextBox>
<asp:TextBox ID="txtCurName" runat="server" MaxLength="10" AutoPostBack="True" Width="428px"></asp:TextBox>
//--点这个铵扭
<asp:Button ID="butOpen" runat="server" Text="打开" OnClick="butOpen_Click" CausesValidation="False" Width="78px" />
//-------------Unit.aspx.cs 文件
protected void butOpen_Click(object sender, EventArgs e)
{
DAL.CommDAL.ShowComBox(this, 32, 25, "form1", "txtCurNo", "txtCurName", "OnQueryCode", "Unit", "单位编号");
}
//this 由于public partial class Unit : System.Web.UI.Page 所以这个this指的是System.Web.UI.Page
//form1 指的是:<body> <form id="form1" runat="server" >
//"txtCurNo", "txtCurName", 是指文本框的ID值
//"OnQueryCode" 是指脚本的名字
//Unit 是指: 文件名
//"单位编号" 是指:文本框的标签.
//-----------CommDAL.cs 文件
public static void ShowComBox(System.Web.UI.Page page, int height, int width, string formName, string txtCode, string txtName, string scriptName, string tableName, string lblName)
{
string scriptString = "<script language=javascript>";
scriptString += "var arg = window.showModalDialog( '../SystemFrameWorks/CommonQuery.aspx?tableName=" + tableName + "&lblName=" + lblName + "&ts='+Date() ,'','dialogHeight:45;dialogWidth:55;center:1;scroll:on ;resizable:yes');";
scriptString += "if (arg != null) { ";
scriptString += "if (" + formName + ".elements['" + txtCode + "']!=null){" + formName + ".elements['" + txtCode + "'].value = arg[0];} ";
scriptString += "if (" + formName + ".elements['" + txtName + "']!=null){" + formName + ".elements['" + txtName + "'].value = arg[1];} ";
scriptString += "if (" + formName + ".elements['butLoadData']!=null){" + formName + ".elements['butLoadData'].click();}} ";
scriptString += "</script>";
if (!page.IsStartupScriptRegistered(scriptName))
page.RegisterStartupScript(scriptName, scriptString);
}
//--------------CommonQuery.aspx 文件
<asp:TemplateField HeaderText="选 择">
<ItemStyle Width="60px" Height="30px" />
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl="../images/choose.gif" ID="delid" CommandName="del" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
//-------CommonQuery.aspx 文件----------------点击按钮后返回对话框中的值.
protected void gridData_RowCommand(object sender, GridViewCommandEventArgs e)
{
ImageButton lb = (ImageButton)e.CommandSource;
GridViewRow curgvr = (GridViewRow)lb.Parent.Parent;
string aa = curgvr.Cells[1].Text.ToString();
string aaa = curgvr.Cells[2].Text.ToString();
string tableName = Request.QueryString["tableName"].Trim();
string output = "<script>var arr=new Array(); arr[0]='" + aa + "'; arr[1]='" + aaa +
"'; window.returnValue = arr;" + " window.close(); </script>";
output = output.Replace(" ", "");
Response.Write(output);