asp.net彈出窗口 返回值
Page.aspx:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無標(biāo)題頁</title>
<script type="text/javascript" >...
function Pop()
...{
var result=showModalDialog('downs.aspx','subpage','dialogWidth:400px;dialogHeight:300px;center:yes;help:no;resizable:no;status:no'); //打開模態(tài)子窗體,并獲取返回值
document.getElementById("txt_id").value=result.split("'")[0]; //返回值分別賦值給相關(guān)文本框
document.getElementById("txt_name").value=result.split("'")[1];
document.getElementById("txt_pwd").value=result.split("'")[2];
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txt_id" runat="server" ></asp:TextBox>
<asp:TextBox ID="txt_name" runat="server" ></asp:TextBox>
<asp:TextBox ID="txt_pwd" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="btnPop" runat="server" Text="PoPWindows" />
</div>
</form>
</body>
</html>
downs.aspx: 彈出頁面
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>無標(biāo)題頁</title>
<script type="text/javascript" >...
function cc(infor_id,infor_name,infor_psw) //參數(shù)分別為id,name和password
...{
window.returnValue= infor_id+"'"+infor_name+"'"+infor_psw; //返回值
window.close();
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gvshow" runat="server" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" Horiz />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
downs.cs:彈出頁面后臺(tái)代碼:
public partial class downs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetBind();
}
}
public void SetBind()
{
string ConnString = ConfigurationManager.ConnectionStrings["ConnStr"].ToString();
using (SqlConnection conn = new SqlConnection(ConnString))
{
conn.Open();
string sql = "select top 10 gwid,machtype,isok from allinfor";
SqlDataAdapter ada = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
ada.Fill(ds);
gvshow.DataSource = ds.Tables[0];
this.gvshow.DataBind();
}
}
protected void gvshow_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick", "cc('" + e.Row.Cells[0].Text + "','" + e.Row.Cells[1].Text + "','" + e.Row.Cells[2].Text + "')");
}
}
}
第二種方式:
returnValue是javascript中html的window對(duì)象的屬性,目的是返回窗口值,當(dāng)用
window.showModalDialog函數(shù)打開一個(gè)IE的模式窗口(模式窗口知道吧,就是打開后不能操作父窗口,只能等模式窗口關(guān)閉時(shí)才能操作)時(shí),用于返回窗口的值,下面舉個(gè)例子:
//father.html
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script language="javascript">
function showmodal(){
var ret = window.showModalDialog("child.htm",null,"dialogWidth:350px;dialogHeight:350px;help:no;status:no");
if (ret){alert('子窗口返回真!');
}else{
alert('子窗口返回假!');
}
}
</script>
</HEAD>
<BODY>
<INPUT id=button1 type=button value=Button name=button1 onclick="showmodal();">
</BODY>
</HTML>
//child.html
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<script language="javascript">
function trans(tag){
if (tag==0){
window.returnValue=false;
} else{
window.returnValue =true;
}
window.close();
}
</script>
</HEAD>
<BODY>
<INPUT id=button1 type=button value="返回真" name=button1 onclick="trans(1)">
<INPUT id=button2 type=button value="返回假" name=button2 onclick="trans(0)">
</BODY>
</HTML>
這樣一來可以實(shí)現(xiàn)從模式窗口向父窗口傳遞值的作用,
這個(gè)returnValue除了可以是布爾值,整型值等以外還可以是個(gè)js數(shù)組,用來傳遞大量數(shù)據(jù)。
具體showModalDialog等的用法,可以參考msdn。
注意下面的有opener的都只能是用在window.open()這種情況而不能是上面.的showModel...等形式否則的話.會(huì)報(bào)undetife錯(cuò)誤....
也可以這樣子的改變父窗口中的值. 下面的這個(gè)..可以動(dòng)態(tài)改變父窗口中多個(gè)值.而不是簡單的把彈出窗口中的一個(gè)選中以后.馬上就傳回去給父窗口.
opener.document.getElementById('txt_Phone').value = Number;
opener.document.getElementById('hdn_ID').value = ID;
opener.document.getElementById('hdn_Phone').value = Number;
window.close();
加上這句.我們還可以.刷新父窗口
window.opener.location.href=window.opener.location.href
window.opener.location.reload()
如果還要調(diào)用父窗口中的方法.也可以用下面的這種..如下
opener.函數(shù)名(xxx,xxx)
不過函數(shù)內(nèi)變量的作用域仍為父窗體.
這樣子我們.就可以直接調(diào)用這個(gè)函數(shù)..如果這個(gè)函數(shù)是異步請(qǐng)求的那就更爽了..
也就是說我們.在子窗口中可以向服務(wù)器發(fā)送請(qǐng)求..關(guān)閉子窗口后..我們父窗口又立即向服務(wù)器發(fā)送異步請(qǐng)求.又窗口雙請(qǐng)求.
相關(guān)文章
巧用ASP.NET預(yù)編譯Web應(yīng)用程序規(guī)避調(diào)用延遲的方法
ASP.NET 1.x的開發(fā)人員常常聽到用戶抱怨首次調(diào)用應(yīng)用程序的時(shí)候會(huì)碰到初始化延遲。畢竟,初次請(qǐng)求會(huì)引發(fā)一個(gè)系列過程,包括運(yùn)行庫初始化、分析、把ASPX頁面編譯成中間語言、把方法即時(shí)編譯成本地代碼等等。2011-08-08
.Net語言Smobiler開發(fā)之如何仿微信朋友圈的消息樣式
這篇文章主要介紹了.Net語言Smobiler開發(fā)平臺(tái)如何仿微信朋友圈的消息樣式?本文為大家揭曉答案2016-09-09
ASP.NET?Core中創(chuàng)建中間件的方式匯總
ASP.NET?Core中間件(Middleware)是用于處理HTTP請(qǐng)求和響應(yīng)的組件,它們被安排在請(qǐng)求處理管道中,并按順序執(zhí)行,這篇文章主要介紹了ASP.NET?Core中創(chuàng)建中間件的幾種方式,需要的朋友可以參考下2024-07-07
Coolite Cool Study 3 MVC + Coolite 的實(shí)現(xiàn)代碼
啊,開始以為MVC+Coolite結(jié)合的例子沒什么難度,但原來Coolite在MVC中需要特定設(shè)置一下某些屬性才行,費(fèi)了兩個(gè)小時(shí)才算大功告成,具體請(qǐng)看下文。還是先把這個(gè)例子的效果貼上來再說。2009-05-05
在asp.net core中使用類似Application的服務(wù)的實(shí)現(xiàn)
這篇文章主要介紹了在asp.net core中使用類似Application的服務(wù)的實(shí)現(xiàn),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-02-02
ASP.NET 頁面刷新和定時(shí)跳轉(zhuǎn)代碼整理
很多是摘網(wǎng)上的但是我整理了一下。以便以后查閱。2009-12-12
.NET性能優(yōu)化之為結(jié)構(gòu)體數(shù)組使用StructLinq的問題解析
這篇文章主要介紹了.NET性能優(yōu)化為結(jié)構(gòu)體數(shù)組使用StructLinq,本系列的主要目的是告訴大家在遇到性能問題時(shí),有哪些方案可以去優(yōu)化;并不是要求大家一開始就使用這些方案來提升性能,需要的朋友可以參考下2022-05-05
使用VSCode開發(fā)和調(diào)試.NET Core程序的方法
這篇文章主要介紹了使用VSCode開發(fā)和調(diào)試.NET Core程序的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
ASP.NET三層架構(gòu)詳解 如何實(shí)現(xiàn)三層架構(gòu)
這篇文章主要為大家詳細(xì)介紹了ASP.NET三層架構(gòu),如何實(shí)現(xiàn)三層架構(gòu),本文為大家揭曉,感興趣的小伙伴們可以參考一下2016-05-05

