asp.net 彈出對(duì)話框返回多個(gè)值

圖中,姓名有英文和中文之分。當(dāng)用戶單擊對(duì)話框中的選擇按鈕時(shí),就可以返回給父對(duì)話框了。
下面說代碼了:
這里共包含3個(gè)頁面
結(jié)構(gòu)如下圖:
其中Default.aspx的代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>彈出選擇窗口</title>
<script language="javascript" type="text/javascript"><!--
function ShowDialog(ch,en,src)
{
var array=new Array();
array[0]=document.getElementById(ch);
array[1]=document.getElementById(en);
showModalDialog(src,array,"resizable:yes;");//src 為彈出頁面,array 傳過去的參數(shù)。
}
// --></script>
</head>
<body>
<form id="form1" runat="server">
<table border="1px">
<tr>
<td> </td>
<td style="text-align:center;" style="text-align:center;">中文</td>
<td style="text-align:center;" style="text-align:center;">英文</td>
<td> </td>
</tr>
<tr>
<td>姓名:</td>
<td><asp:TextBox ID="chTxtName" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="enTxtName" runat="server"></asp:TextBox></td>
<td><input type="button" id="btnChoiceName" value="選擇" onclick="ShowDialog('chTxtName','enTxtName','Frame.aspx');" /></td>
</tr>
</table>
</form>
</body>
</html>
其中javascript 彈出modaldialog,并且傳過去是一個(gè)數(shù)組,數(shù)組中包含對(duì)象。這樣就實(shí)現(xiàn)了,同時(shí)傳多個(gè)值了。
然后我使用了框架,使用了框架才能解決彈出的頁面GridView.aspx無法傳值和緩存的問題了。
下面看Frame.aspx的代碼,也很簡單,無后臺(tái)代碼,只是一個(gè)iframe
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>框架</title>
</head>
<body>
<form id="form1" runat="server">
<iframe id="gridview" src="GridView.aspx" src="GridView.aspx" style="position:relative;width:100%;" scrolling="no" frameborder="0" onload="document.getElementById('gridview').style.height=(gridview.document.body.scrollHeight+20)+'px'"></iframe>
</form>
</body>
</html>
這個(gè)iframe是自適應(yīng)大小的。通過onload事件實(shí)現(xiàn)的。
好了,看GridView.aspx頁面吧。
其代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView</title>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td>
<asp:TextBox ID="txtChName" runat="server"></asp:TextBox></td>
<td>
<asp:TextBox ID="txtEnName" runat="server"></asp:TextBox></td>
<td style="width: 164px">
<asp:Button ID="btnNew" runat="server" Text="新建" OnClick="btnNew_Click" /></td>
</tr>
<tr>
<td colspan="3">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting" Width="359px" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
<Columns>
<asp:BoundField DataField="chName" HeaderText="中文" />
<asp:BoundField DataField="enName" HeaderText="英文" />
<asp:CommandField ShowEditButton="True" >
<ControlStyle Width="100px" />
</asp:CommandField>
<asp:CommandField ShowSelectButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<EmptyDataTemplate>
無數(shù)據(jù)
</EmptyDataTemplate>
<FooterStyle BackColor="Tan" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
在這個(gè)頁面里可以新建、插入、刪除和更新。單擊選擇時(shí)就可以返回了,當(dāng)單擊選擇時(shí)觸發(fā)下面的事件:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string chName = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
string enName = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
Response.Write("<:script language=\"javascript\">
window.dialogArguments[0].value='" + chName + "';window.dialogArguments[1].value='" + enName + "';window.close();<script>");
}
上面的代碼就是返回的重點(diǎn);window.dialogArguments實(shí)際上就是我們剛剛傳過來的array數(shù)組。所以它有2個(gè)對(duì)象,這2個(gè)對(duì)象就是我們要賦值的對(duì)象。通過這一句就可以達(dá)到我們的目的了。
提供原代碼下載:其中包括數(shù)據(jù)庫。
- .NET中彈出對(duì)話框的方法匯總
- asp.net GridView 刪除時(shí)彈出確認(rèn)對(duì)話框(包括內(nèi)容提示)
- 兩種WEB下的模態(tài)對(duì)話框 (asp.net或js的分別實(shí)現(xiàn))
- ASP.NET AJAX時(shí)用alert彈出對(duì)話框
- Asp.net 彈出對(duì)話框基類(輸出alet警告框)
- asp.net下模態(tài)對(duì)話框關(guān)閉之后繼續(xù)執(zhí)行服務(wù)器端代碼的問題
- ASP.NET中彈出消息框的幾種常見方法
- .net 彈出消息框后導(dǎo)致頁面樣式變亂解決方法
- 基于.Net實(shí)現(xiàn)前端對(duì)話框和消息框
相關(guān)文章
開源跨平臺(tái)運(yùn)行服務(wù)插件TaskCore.MainForm
這篇文章主要為大家詳細(xì)介紹了開源跨平臺(tái)運(yùn)行服務(wù)插件TaskCore.MainForm的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06
asp.net 仿騰訊微薄提示 還能輸入*個(gè)字符 的實(shí)現(xiàn)代碼
asp.net 仿騰訊微薄提示 還能輸入*個(gè)字符 的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-10-10
MVC+EasyUI+三層新聞網(wǎng)站建立 tabs標(biāo)簽制作方法(六)
這篇文章主要為大家詳細(xì)介紹了MVC+EasyUI+三層新聞網(wǎng)站建立的第六篇,教大家如何制作tabs標(biāo)簽,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
datagrid行內(nèi)按鈕(更新/刪除等)操作實(shí)現(xiàn)代碼
datagrid控件想必大家很是熟悉,本文將介紹下datagrid行內(nèi)按鈕的操作更新/刪除等等,感興趣的你可不要錯(cuò)過了哈,希望本文知識(shí)點(diǎn)可以幫助到你2013-02-02
利用AJAX與數(shù)據(jù)島實(shí)現(xiàn)無刷新綁定
利用AJAX與數(shù)據(jù)島實(shí)現(xiàn)無刷新綁定...2007-03-03
Asp.Net 網(wǎng)站優(yōu)化系列之?dāng)?shù)據(jù)庫優(yōu)化分字訣上 分庫
當(dāng)我們的數(shù)據(jù)量很小的時(shí)候,我們會(huì)把用戶表,博客表,論壇表,閃存表等等都砸在一個(gè)庫里,我們的業(yè)務(wù)增長的很好,在不久之后我們盡力的優(yōu)化了查詢,但是效果依然不佳,這時(shí)候用分字訣的時(shí)機(jī)到了。2010-06-06

