[ASP.NET]如何点击按钮弹出新窗口,输入数据后返回并刷新页面?(C#代码)

限时加码!20+主流AI编程工具免费用 购周边加赠Coding Plan Lite,Claude Code、Cursor等即刻畅享,学习进阶更高效! 阅读详情

翻译自孟宪会之精彩世界的VB.NET代码
http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4

Webform1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm1" %>

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm1</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
 </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" Width="96px" Text="打开窗口2"></asp:button>
    <asp:button id="Button2" runat="server" Width="96px" Text="打开窗口4"></asp:button></form>
  </div>
 </body>
</HTML>


Webform1.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ShowModalTest
{
 /// <summary>
 /// WebForm1 的摘要说明。
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label Label1;
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.HtmlControls.HtmlForm Form1;
  protected System.Web.UI.WebControls.Button Button1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   // 在此处放置用户代码以初始化页面
    string strScript= "/n";
    if (!IsClientScriptBlockRegistered("clientScript"))
    {
     strScript = "<script>/n";
     strScript += "function OpenWin(){/n";
     strScript += "var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value,'help:no')/n";
     strScript += "if(str!=null)  document.Form1.TextBox1.value=str/n";
     strScript += "}/n";
     strScript += "</script>/n";
     RegisterClientScriptBlock("clientScript", strScript);
    }
     if (!IsClientScriptBlockRegistered("clientScript2"))
    {
     strScript = "<script>/n";
     strScript += "function OpenWin2(){/n";
     strScript += "var str=window.showModalDialog('WebForm4.aspx',document.Form1.TextBox1.value,'help:no')/n";
     strScript += "if(str!=null)  document.Form1.TextBox1.value=str/n";
     strScript += "}/n";
     strScript += "</script>/n";
     RegisterClientScriptBlock("clientScript2", strScript);
    }
    Button1.Attributes.Add("onclick", "OpenWin()");
    Button2.Attributes.Add("onclick", "OpenWin2()");

  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
 }
}



Webform2.aspx
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm2" %> <%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.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>
 <frameset rows="0,*">
  <frame src="about:blank">
  <frame src="WebForm3.aspx">
 </frameset>
</HTML>

WebForm3.aspx
<%@ Page language="c#" Codebehind="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.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="320px"></asp:TextBox><br>
   <br>
   <asp:Button id="Button1" runat="server" Text=" 提  交 "></asp:Button>
  </form>
 </body>
</HTML>
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm1" %>
WebForm3.aspx.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ShowModalTest
{
 /// <summary>
 /// WebForm3 的摘要说明。
 /// </summary>
 public class WebForm3 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Label Label1;
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.WebControls.Button Button1;
  protected System.Web.UI.HtmlControls.HtmlControl MyBody;
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(IsPostBack)
   {
    string strScript = "<script>/n";
    strScript += "window.parent.returnValue='" + TextBox1.Text.Replace("'", "/'") + "'/n";
    strScript += "window.parent.close()/n";
    strScript += "</script>/n";
    if (!IsClientScriptBlockRegistered("clientScript"))
     RegisterClientScriptBlock("clientScript", strScript);
   }
   else
   {
    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 System.EventHandler(this.Page_Load);

  }
  #endregion
 }
}

Webform4.aspx
<%@ Page language="c#" Codebehind="WebForm4.aspx.cs" AutoEventWireup="false" Inherits="ShowModalTest.WebForm4" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm4</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">
  <form id="Form1" method="post" runat="server">
   <iframe frameborder="no" src='WebForm3.aspx' style="WIDTH: 368px; HEIGHT: 192px"></iframe>
  </form>
 </body>
</HTML>

ASP.NET(用c#),弹出文件保存对话框窗口 由于要做一个mp3下载的东西,单击下载,会被Media Player打开播放, 保存不了,甚是不便,网上搜了半天,终于找到解决方案,现帖出来给大家。 try...{  FullFileName = Server.MapPath(FileName);  //FileName--要下载的文件名  FileInfo DownloadFile= new FileInfo(FullFileNam 阅读详情

相关推荐

HTML弹出窗口自动点击按钮实现全攻略

场景是否允许脚本操作说明同源页面是可正常操作 DOM跨域 iframe 页面否受同源策略限制新窗口打开的页面否除非页面允许访问通过浏览器扩展访问是扩展具有更高权限解决方案建议:- 使用浏览器扩展实现更高权限的自动化。- 与目标网站合作设置CORS或CSP白名单。- 使用 Puppeteer 等无头浏览器进行自动化测试。

weixin_29997223的博客 1540

C# ASP.NET中无刷新页面 弹出对话框,页面跳转

C# ASP.NET中无刷新页面弹出对话框,页面跳转   ScriptManager.RegisterStartupScript(this, this.GetType(), "错误!", "alert('初始等级要小于要练的等级!');window.location='ItemsPage.aspx'", true); .NET客户端的数据验证实例 asp.net代码块   

无心人的终点 2644

如何点击按钮弹出新窗口输入数据返回刷新页面?(C#代码)

翻译自孟宪会之精彩世界的VB.NET代码http://dotnet.aspx.cc/ShowDetail.aspx?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4原文链接 http://xujh.cnblogs.com/archive/2004/11/17/65009.aspxWebform1.aspx

stu_acer的专栏 7656

如何点击按钮弹出新窗口输入数据返回刷新页面

如何点击按钮弹出新窗口输入数据返回刷新页面? 作者:孟宪会出自:【孟宪会之精彩世界】发布日期:2003年7月8日 4点0分13秒 ...

weixin_34293246的博客 504

如何点击按钮弹出新窗口输入数据返回刷新页面

如何点击按钮弹出新窗口输入数据返回刷新页面?作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年7月8日 4点0分13秒 在一些.NET论坛中有人经常会问:如何在页面点击按钮打开新页面输入数据,然后返回到初始页面进行更新?要解决这个问题,应该弄清楚window.showModalDialog()的用法,本人在http://www.csd

徐虎的专栏 1792

10种asp.net页面弹出提示信息

1.ClientScript.RegisterStartupScript(GetType(),"message","alert('第一种方式,无白屏!');"); 2.HttpContext.Current.Response.Write("alert('第二种方式,有白屏!')"); 3.public static void Show(System.Web.UI.Page page, stri

lockelk的专栏 2712

页面提示以及页面刷新

页面刷新前先提示后跳转 Response.Write("<script>alter('提交成功!')</script>");Response.Write("<script>window.location.href='MaintainSupplierCompany.aspx'</script>"); 在Load事件里写:(就可以在单击bt...

dcl12753的博客 815

C# .NET 之GridView上弹出页面方法

目标:A.aspx页面弹出页面B.aspx 两个页面之间通过传递GuidProject为桥梁前提:已画好这两个页面 一:在A页面上设置一个按钮 (或者连接)的动作事件e.g.:uwToolbar_Click二:在A页面页面文件的开头(所有引用的结束)加入:function uwToolbar_Click(oToolbar, oButton, oEvent)//动作事件方法名{        sw

ygjdatou的专栏 1071

ASP.NET弹出消息框

研究怎么弹出消息框,找不到C#后台弹出消息框的方法,只有借助JS脚本才能包装出弹出的效果,我们来看下怎么在页面弹出消息框。   ***JS弹出消息框***   语法: alert('');   描述:alert()属于JavaScript中Window对象的

cyy089074316的专栏 9580

利用.NET代碼實現點擊按鈕彈出新窗體,輸入數據后返回刷新頁面

      利用.NET代碼實現點擊按鈕彈出新窗體,輸入數據后返回刷新頁面,網上大部份都是JavaScript實現,為使用方便,本人將其封裝進一段.NET代碼中。只所以稱作.net代碼,是因為C#/VB各一份嘍:)      也是因為自己的項目中要用到一項類似於Winform的Messagebox.ShowDialog這樣的功能,起初以為跟Winform差不了多少的,誰知做的時候卻出現了很多"...

weixin_34418883的博客 142

ASP.NET中在HTML中嵌入C#代码的方法

一.使用在HTML中嵌入C#代码 打开ASPX页面Default.aspx,首先在 之间添加标题“使用%HTML中嵌入C#“,再在其中的 标签中间输入以下代码: title>使用%HTML中嵌入C#title> … div>             int i;             for (i = 0; i             {              

gscaiyucheng的专栏 1万+

asp.net弹出层实例

操作一 操作二 操作四 操作五 <div id="divNewBlock" style=" border:solid 1px;padding:10px;width:600px;z-index:1001; position: absolute; display:none;top:50%

张亚运的专栏 3253

Asp.net页面跳转的方法

Asp.net几种页面跳转的方法 在asp.net下,经常需要页面的跳转,下面是具体的几种方法。跳转页面是大部编辑语言中都会有的,正面我们来分别介绍一下关于.net中response.redirect sever.execute server.transfer 三种页面跳转的方法 ①response.redirect (慢!但全能!) 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次postback),但他可以跳 转到任何页面,没有站点页面限制(即可以由雅虎跳到新浪),同时不

weixin_45664856的博客 5912

NET中关闭弹出窗口刷新页面

案例1:父页面A.aspx弹出窗口B.aspx;关闭B.aspx页面刷新A.aspx;在B.aspx的点击关闭按钮时执行下列代码: string popupScript = "" + "alert('Submit successfully!');window.opener.document.forms[0].submit();window.opener =null;window.clo

Miracle_Lee 1623
上一篇: 重新指定FormsAuthentication Redirect到的页面
下一篇: [ASP.NET]实现在执行完服务端代码后弹出提醒对话框
nehu
博客等级 码龄23年 1粉丝 10原创
评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值