随笔-13  评论-0  文章-0  trackbacks-0

WebForm2.aspx:

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="ChenFeng.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm2</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <div align="center"><form id="Form1" method="post" runat="server">
    <asp:label id="Label1" runat="server" font-bold="true">
    从当前页面打开新窗口,并把变量传递到新窗口的例子,可以多次打开提交。
    </asp:label><br>
    <br>
    <asp:textbox id="TextBox1" runat="server" width="600px"></asp:textbox><br>
    <br>
    <asp:button id="Button1" runat="server" text="打开窗口" width="96px"></asp:button></form>
  </div>
 </body>
</HTML>


WebForm2.aspx.cs


using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace ChenFeng
{
 /// <summary>
 /// WebForm2 的摘要说明。
 /// </summary>
 public class WebForm2 : Page
 {
  protected Label Label1;
  protected TextBox TextBox1;
  protected Button Button1;
  protected HtmlForm Form1;

  private void Page_Load(object sender, EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if (!IsClientScriptBlockRegistered("clientScript"))
   {
    string strScript = "<script>{"+"\r\n";
    strScript += "function OpenWin(){" + "\r\n";
    strScript += "var str=window.showModalDialog('WebForm3.aspx',document.Form1.TextBox1.value)" + "\r\n";
    strScript += "if(str!=null)  document.Form1.TextBox1.value=str" + "\r\n";
    strScript += "}" + "\r\n";
    strScript += "}</script>" + "\r\n";
    RegisterClientScriptBlock("clientScript", strScript);
   }
   Button1.Attributes.Add("onclick", "OpenWin()");

  }

  #region Web 窗体设计器生成的代码

  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }

  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.Load += new EventHandler(this.Page_Load);

  }

  #endregion
 }
}


WebForm3.axpx

<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="ChenFeng.WebForm3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm3</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout" id="MyBody" runat="server">
  <form id="Form1" method="post" runat="server">
   <asp:label id="Label1" runat="server">请输入您的大名:</asp:label><br>
   <br>
   <asp:textbox id="TextBox1" runat="server" width="558"></asp:textbox><br>
   <br>
   <asp:button id="Button1" runat="server" text=" 提  交 "></asp:button></form>
 </body>
</HTML>

WebForm3.aspx.cs

using System;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ChenFeng
{
 /// <summary>
 /// WebForm3 的摘要说明。
 /// </summary>
 public class WebForm3 : Page
 {
  protected Label Label1;
  protected TextBox TextBox1;
  protected Button Button1;
  protected System.Web.UI.HtmlControls.HtmlControl MyBody;

  private void Page_Load(object sender, EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if (IsPostBack)
   {
    string strScript = "<script>{" + "\r\n";
    strScript += "window.parent.returnValue='" + TextBox1.Text.Replace("'", "\'") + "'" + "\r\n";
    strScript += "window.parent.close()" + "\r\n";
    strScript += "}</script>" + "\r\n";
    if (! IsClientScriptBlockRegistered("clientScript"))
    {
     RegisterClientScriptBlock("clientScript", strScript);
    }
   }
   if (! IsPostBack)
   {
    MyBody.Attributes.Add("onload", "document.Form1.TextBox1.value=window.parent.dialogArguments");
   }

  }

  #region Web 窗体设计器生成的代码

  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }

  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {
   this.Load += new EventHandler(this.Page_Load);

  }

  #endregion
 }
}

posted on 2006-05-29 09:08 CqRandy 阅读(685) 评论(0)  编辑 收藏 引用 所属分类: ASP.NET 1.1
只有注册用户登录后才能发表评论。