父窗口中前台代码:
<%
...
@PageLanguage="C#"AutoEventWireup="true"CodeFile="testwebpart.aspx.cs"Inherits="wss_testwebpart"
%>
<! DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//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" > ...
vargetreturnvalue=null;
functionshowModelWindow()
...{
vara=(screen.height-400)/2;
varb=(screen.width-500)/2;
varshowvalue=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();
}
}
functionbuttonClick()
...{
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 ="DataSource=XWW;InitialCatalog=Testdb;UserID=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 >
<! DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//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" > ...
vargetreturnvalue=null;
functionshowModelWindow()
...{
vara=(screen.height-400)/2;
varb=(screen.width-500)/2;
varshowvalue=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();
}
}
functionbuttonClick()
...{
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 ="DataSource=XWW;InitialCatalog=Testdb;UserID=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
... {
protectedvoidPage_Load(objectsender,EventArgse)
...{
if(Request.Form["Hidden1"]!=null)
...{
this.GridView1.DataSourceID="SqlDataSource1";
this.GridView1.DataBind();
}
}
protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse)
...{
this.GridView1.PageIndex=e.NewPageIndex;
Response.Write(e.NewPageIndex.ToString());
this.GridView1.DataBind();
}
protectedvoidButton4_Click(objectsender,EventArgse)
...{
Response.Write(Request.Form["Hidden1"].ToString());
}
}
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
... {
protectedvoidPage_Load(objectsender,EventArgse)
...{
if(Request.Form["Hidden1"]!=null)
...{
this.GridView1.DataSourceID="SqlDataSource1";
this.GridView1.DataBind();
}
}
protectedvoidGridView1_PageIndexChanging(objectsender,GridViewPageEventArgse)
...{
this.GridView1.PageIndex=e.NewPageIndex;
Response.Write(e.NewPageIndex.ToString());
this.GridView1.DataBind();
}
protectedvoidButton4_Click(objectsender,EventArgse)
...{
Response.Write(Request.Form["Hidden1"].ToString());
}
}
子窗口中前台代码:
<%
...
@PageLanguage="C#"AutoEventWireup="true"CodeFile="xwwtest.aspx.cs"Inherits="wss_xwwtest"
%>
<! DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//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" > ...
functionreturnvalue()
...{
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 >
<! DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//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" > ...
functionreturnvalue()
...{
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
... {
protectedvoidPage_Load(objectsender,EventArgse)
...{
}
protectedvoidButton1_Click(objectsender,EventArgse)
...{
inti=0;
SqlConnectioncon=newSqlConnection("server=xww;database=testdb;uid=sa;pwd=admin");
con.Open();
stringcmdtxt="UPDATEtestSETname='"+this.TextBox2.Text+"',subject='"+this.TextBox3.Text+"'whereid="+this.TextBox1.Text.Trim()+"";
SqlCommandcom=newSqlCommand(cmdtxt,con);
i=com.ExecuteNonQuery();
if(i!=0)
...{
Response.Write("<scriptlanguage='javascript'>alert('修改成功!');window.returnValue='ceshi';window.close();</script>");
//Session["IsGood"]="1";
}
else
...{
Response.Write("<scriptlanguage='javascript'>alert('修改失败!')</script>");
}
}
}
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
... {
protectedvoidPage_Load(objectsender,EventArgse)
...{
}
protectedvoidButton1_Click(objectsender,EventArgse)
...{
inti=0;
SqlConnectioncon=newSqlConnection("server=xww;database=testdb;uid=sa;pwd=admin");
con.Open();
stringcmdtxt="UPDATEtestSETname='"+this.TextBox2.Text+"',subject='"+this.TextBox3.Text+"'whereid="+this.TextBox1.Text.Trim()+"";
SqlCommandcom=newSqlCommand(cmdtxt,con);
i=com.ExecuteNonQuery();
if(i!=0)
...{
Response.Write("<scriptlanguage='javascript'>alert('修改成功!');window.returnValue='ceshi';window.close();</script>");
//Session["IsGood"]="1";
}
else
...{
Response.Write("<scriptlanguage='javascript'>alert('修改失败!')</script>");
}
}
}
在修改一条数据时,为了使弹出的页面及时地得到最新数据,应该清空弹出页面中缓存,所以还应该在页面中添加以下代码,使页面不存在缓存.限制页面读取本地缓存
<
META
HTTP-EQUIV