父窗口中前台代码:
<% ... @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " testwebpart.aspx.cs " Inherits = " wss_testwebpart " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > < script language ="javascript" type ="text/javascript" > ... var getreturnvalue = null ; function showModelWindow() ... { var a = (screen.height - 400 ) / 2 ; var b = (screen.width - 500 ) / 2 ; var showvalue = window.showModalDialog( ' xwwtest.aspx ' , ' newwindow ' , ' dialogWidth:700px;scroll:no;dialogHeight:550px,top= ' + a + ' ,left= ' + b + ' ,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no ' ); if (showvalue != null ) ... { document.getElementById( " Hidden1 " ).value = showvalue; getreturnvalue = showvalue; document.getElementById( " Button1 " ).onclick = buttonClick(); } } function buttonClick() ... { document.form1.submit(); } </ script > </ head > < body > < form id ="form1" runat ="server" > < div > < a href ="#" onclick ="showModelWindow()" > 测试 </ a > < br /> < br /> < br /> < br /> gfdgfdgdfgdfgfdgfdsgdsgfdsgdgfds< br /> < br /> < br /> < input id ="Button1" name ="btntest" type ="button" value ="button" onclick ="buttonClick()" /> < asp:Button ID ="Button2" runat ="server" Text ="Button" />< br /> < br /> < asp:GridView ID ="GridView1" runat ="server" AllowPaging ="True" AutoGenerateColumns ="False" DataSourceID="SqlDataSource1" OnPageIndexChanging ="GridView1_PageIndexChanging" PageSize="4" > < Columns > < asp:BoundField DataField ="id" HeaderText ="id" InsertVisible ="False" ReadOnly ="True" SortExpression="id" /> < asp:BoundField DataField ="name" HeaderText ="name" SortExpression ="name" /> < asp:BoundField DataField ="subject" HeaderText ="subject" SortExpression ="subject" /> < asp:BoundField DataField ="Source" HeaderText ="Source" SortExpression ="Source" /> </ Columns > </ asp:GridView > < input id ="Hidden1" name ="hiddenvalue" type ="hidden" runat ="server" /> < input id ="Text1" type ="text" />< br /> < asp:SqlDataSource ID ="SqlDataSource1" runat ="server" ConnectionString ="Data Source=XWW;Initial Catalog=Testdb;User ID=sa;Password=admin" ProviderName="System.Data.SqlClient" SelectCommand ="SELECT * FROM [Test]" ></ asp:SqlDataSource > < input id ="Button3" type ="button" value ="button" onclick ="getvalue()" /> < asp:Button ID ="Button4" runat ="server" OnClick ="Button4_Click" Text ="Button" /> </ div > </ form > </ body > </ html >
父窗口中后台代码:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class wss_testwebpart : System.Web.UI.Page ... { protected void Page_Load( object sender, EventArgs e) ... { if (Request.Form[ " Hidden1 " ] != null ) ... { this .GridView1.DataSourceID = " SqlDataSource1 " ; this .GridView1.DataBind(); } } protected void GridView1_PageIndexChanging( object sender, GridViewPageEventArgs e) ... { this .GridView1.PageIndex = e.NewPageIndex; Response.Write(e.NewPageIndex.ToString()); this .GridView1.DataBind(); } protected void Button4_Click( object sender, EventArgs e) ... { Response.Write(Request.Form[ " Hidden1 " ].ToString()); } }
子窗口中前台代码:
<% ... @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " xwwtest.aspx.cs " Inherits = " wss_xwwtest " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > < base target ="_self" /> < script language ="javascript" type ="text/javascript" > ... function returnvalue() ... { window.returnValue = true ; window.close(); } </ script > </ head > < body > < form id ="form1" runat ="server" > < div > < asp:Button ID ="Button1" runat ="server" OnClick ="Button1_Click" Text ="返回" />< br /> < br /> < input id ="Button2" type ="button" value ="返回值" onclick ="returnvalue()" /> < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox > < asp:TextBox ID ="TextBox2" runat ="server" ></ asp:TextBox > < asp:TextBox ID ="TextBox3" runat ="server" ></ asp:TextBox ></ div > </ form > </ body > </ html >
子窗口中后台代码:
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; public partial class wss_xwwtest : System.Web.UI.Page ... { protected void Page_Load( object sender, EventArgs e) ... { } protected void Button1_Click( object sender, EventArgs e) ... { int i = 0 ; SqlConnection con = new SqlConnection( " server=xww;database=testdb;uid=sa;pwd=admin " ); con.Open(); string cmdtxt = " UPDATE test SET name=' " + this .TextBox2.Text + " ',subject=' " + this .TextBox3.Text + " ' where id= " + this .TextBox1.Text.Trim() + "" ; SqlCommand com = new SqlCommand(cmdtxt,con); i = com.ExecuteNonQuery(); if (i != 0 ) ... { Response.Write( " <script language='javascript'>alert('修改成功!');window.returnValue='ceshi';window.close();</script> " ); // Session["IsGood"] = "1"; } else ... { Response.Write( " <script language='javascript'>alert('修改失败!')</script> " ); } } }
在修改一条数据时,为了使弹出的页面及时地得到最新数据,应该清空弹出页面中缓存,所以还应该在页面中添加以下代码,使页面不存在缓存.限制页面读取本地缓存
< META HTTP-EQUIV ="PRAGMA" CONTENT ="NO-CACHE" >