求c#原代码 如何点击按钮弹出新窗口,输入数据后返回并刷新页面

tdrc_qyh 2003-11-29 06:36:20
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=49ML4AO8-5PB3-4KNY-NJZD-LJOIOXV4M1X4
这个网爷是用vb.net写的,我不知道怎么转换成c#下的,我试了很多方法,但不行,可以打开窗口,但关闭了窗口,而且无法传值,请高手指点,最好是原码。我也看了其他关于这个问题的帖子,但是用脚本我也不熟悉,也搞不出来,请大家帮忙了。
...全文
1240 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tdrc_qyh 2003-11-30
  • 打赏
  • 举报
回复
在问littlehb(网际浪子)一下:我的代码完成了,但还有一个小小的错误,请你和大家看一下:
代码如下
web1.aspx
<%@ Page language="c#" Codebehind="web1.aspx.cs" AutoEventWireup="false" Inherits="test1.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<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">
<FONT face="宋体">
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 247px; POSITION: absolute; TOP: 173px" runat="server" Text="Button"></asp:Button></FONT>
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 208px; POSITION: absolute; TOP: 123px" runat="server"></asp:TextBox>
</form>
</body>
</HTML>
web1.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 test1
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//"<script>window.open('sbgz_edit.aspx?dwm="+dwm+"&sbbh="+sbbh+"&time1="+time1+"','_blank','fullscreen=0,toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,top=0,left=0');</script>"

if(!IsClientScriptBlockRegistered("clientScript"))
{
string strScript = "<script>" ;
strScript +="function OpenWin(){" ;
strScript += "var str=window.showModalDialog('web2.aspx',document.Form1.TextBox1.Value);" ;
strScript += "if(str!=null) document.Form1.TextBox1.value=str;" ;
strScript += "}";
strScript += "</script>" ;
RegisterClientScriptBlock("clientScript", strScript);
}
Button1.Attributes.Add("onclick", "OpenWin()");

}
}
}
web2.aspx
<%@ Page language="c#" Codebehind="web2.aspx.cs" AutoEventWireup="false" Inherits="test1.web3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE></TITLE>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<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="web3.aspx">
</frameset>
</HTML>
web3.aspx
<%@ Page language="c#" Codebehind="web3.aspx.cs" AutoEventWireup="false" Inherits="test1.web3" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<TITLE></TITLE>
<meta content="Microsoft Visual Studio 7.0" 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" id="MyBody" runat="server">
<form id="Form1" method="post" runat="server">
<FONT face="宋体">
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 74px; POSITION: absolute; TOP: 82px" runat="server" Text="Button"></asp:button></FONT><asp:textbox id="TextBox1" style="Z-INDEX: 102; LEFT: 22px; POSITION: absolute; TOP: 15px" runat="server"></asp:textbox></form>
</body>
</HTML>
web3.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 test1
{
/// <summary>
/// web3 的摘要说明。
/// </summary>
public class web3 : System.Web.UI.Page
{
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>";
strScript += "window.parent.returnValue='" + TextBox1.Text.Replace("'", "\'") + "';";
strScript += "window.parent.close();";
strScript += "</script>";
if (!IsClientScriptBlockRegistered("clientScript"))
RegisterClientScriptBlock("clientScript", strScript);
}
if(!IsPostBack)
{
TextBox1.Text="";
MyBody.Attributes.Add("onload", "document.Form1.TextBox1.value=window.parent.dialogArguments");
}
}
}
}
问题是在打开web3的时候,文本框中总是有一个默认的值(undefined),也就是从web1上传不到web3上去,但可以从web3上传到web1上,不知为什么???
tdrc_qyh 2003-11-30
  • 打赏
  • 举报
回复
littlehb(网际浪子) 老大,好象还没有完吧???
还确一个页面的代码呀??
sjzwinfor 2003-11-29
  • 打赏
  • 举报
回复
打开新窗口并传值:
string script1="";
script1 +="<script Language='JavaScript'>";
script1 +="window.open('login0.aspx?tar=zszy'); </script>";
RegisterClientScriptBlock("ClientScript",script1);
return;
wudixiaocaoren 2003-11-29
  • 打赏
  • 举报
回复
webform2.aspx

<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="我的作品输入数据后返回并刷新新页面.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>
wudixiaocaoren 2003-11-29
  • 打赏
  • 举报
回复
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;
using System.Text;
namespace 我的作品输入数据后返回并刷新新页面
{
/// <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.WebControls.Button Button1;
protected System.Web.UI.HtmlControls.HtmlForm Form1;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsClientScriptBlockRegistered("clientScript"))
{
string strScript = "<script>" ;
strScript +="function OpenWin(){" ;
strScript += "var str=window.showModalDialog('WebForm2.aspx',document.Form1.TextBox1.value);" ;
strScript += "if(str!=null) document.Form1.TextBox1.value=str;" ;
strScript += "}";
strScript += "</script>" ;
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 System.EventHandler(this.Page_Load);

}
#endregion
}
}
wudixiaocaoren 2003-11-29
  • 打赏
  • 举报
回复
webform1.aspx

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="我的作品输入数据后返回并刷新新页面.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" 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" Text="打开窗口" Width="96px"></asp:button></form>
</div>
</body>
</HTML>
比尔咔咔 2003-11-29
  • 打赏
  • 举报
回复
上面两句都写在button 的onclick事件中 (都是指aspx文件中)
如 onclick=window.open("edit.aspx");

比尔咔咔 2003-11-29
  • 打赏
  • 举报
回复
这只有javascript或vbscript才能做到和C#或VB.NET无关

window.open("edit.aspx?id="+id+"&planner="+planner,id,"toolbar=no,loction=no,resizeable=no, menubar=no, height=480,width=640");

新窗口中
onclick="window.opener.location.href=window.opener.location.href;window.close()"

62,268

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧