ASP.NET 窗体间传值实现方法详解
假设ParentForm.aspx 页面上有TextBox1文本框和Open按钮
点击Open按钮弹出SubForm.aspx,SubForm.aspx页面上有TextBox1文本框和Close按钮
点击Close按钮关闭SubForm.aspx页面,并把子页面SubForm.aspx文本框的值显示到父页面ParentForm.aspx 的文本框上。
父窗体前台代码:
代码如下 复制代码
<script type="text/javascript">
function OpenSubForm(ret) {
var strPath = "http://www.111Cn.NeT /subForm.aspx"
var nHeight = 500
var nWidth = 500
var feature
feature = "Height= " + nHeight + ",Width=" + nWidth + ",top=30,Left=30";
feature += ",dependent=yes,location=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no;";
window.open(strPath+"?Ret_Form=Form1&Ret_Value="+ret,'subForm',feature).focus();
return false;
}
</script>
父窗体后台代码:
代码如下 复制代码
private void Page_Load(object sender, System.EventArgs e)
{
// ペ?ジを初期化するユ?ザ? コ?ドをここに?啡毪筏蓼?br /> this.Button1.Attributes.Add("onClick","return OpenSubForm('TextBox1');");
}
子窗体后台代码:
代码如下 复制代码
private void Button1_Click(object sender, System.EventArgs e)
{
string strScript =string.Empty;
string strRetForm = String.Empty;
string strRetValue=String.Empty;
strRetForm=Request.Params["Ret_Form"];
strRetValue=Request.Params["Ret_Value"];
if (strRetForm == string.Empty)
{
strRetForm= "document.forms[0]";
}
strScript = "<script language=javascript>";
strScript += "window.opener." + strRetForm;
strScript += "." + strRetValue + ".value='" + this.TextBox1.Text.Trim() + "';";
strScript += "window.close();";
strScript += "</script>";
Response.Write(strScript);
}
上面是js其实也就是页面传值了,下面我把一些页面传值的代码发给大家参考。
页面间传值的几种方式 .
下面的代码片断演示了如何实现这个方法:
源页面WebForm1.aspx.cs中的部分代码:
代码如下 复制代码
private void Button1_Click(object sender, System.EventArgs e)
{
string url;
url="WebForm2.aspx?name=" + TextBox1.Text + "&email=" + TextBox2.Text;
Response.Redirect(url);
}
目标页面WebForm2.aspx.cs中的部分代码:
private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text=Request.QueryString["name"];
Label2.Text=Request.QueryString["email"];
}
使用Session变量
源页面WebForm1.aspx.cs中的部分代码:
代码如下 复制代码
private void Button1_Click(object sender, System.EventArgs e)
{
//textbox1 and textbox2 are webform
//controls
Session["name"]=TextBox1.Text;
Session["email"]=TextBox2.Text;
Server.Transfer("WebForm2.aspx");
}
目标页面WebForm2.aspx.cs中的部分代码:
代码如下 复制代码
private void Page_Load(object sender, System.EventArgs e)
{
Label1.Text=Session["name"].ToString();
Label2.Text=Session["email"].ToString();
Session.Remove("name");
Session.Remove("email");
}
上面两种是常用的其它的就不介绍了,大家可自行去参考
更多详细内容请查看:http://www.111cn.net/net/net/49465.htm
ASP.NET 窗体间传值实现方法详解的更多相关文章
- Asp.Net MVC 扩展 Html.ImageFor 方法详解
背景: 在Asp.net MVC中定义模型的时候,DataType有DataType.ImageUrl这个类型,但htmlhelper却无法输出一个img,当用脚手架自动生成一些form或表格的时候, ...
- asp.net文本编辑器FCKeditor使用方法详解
文本编辑器的使用: 1.FCKeditor的官方网站是:http://www.fckeditor.net/download 目前最新的FCKeditor.Net_2.6.9版本. 请在此页下载:ht ...
- C#窗体间传值的简便方法/工具
一.问题:窗体间传值必须需要窗体之间有联系,具体有如下方式 窗体间传值涉及到窗体A必须拥有窗体B,这样才可以实现A-B之间传值 窗体A与窗体B在窗体/实例C中,A-B可互相通讯 其他方式,不细讨论,复 ...
- Pyqt 窗体间传值
窗体间传值网上有好多方法,比如新建文件,先将子类窗体的数据传到文件中,父窗体读取文件. Signal&Slot机制进行传值 等等 在这里,我们就举个采用apply方法:Signal& ...
- asp.net iis URLRewrite 实现方法详解
原文 asp.net iis URLRewrite 实现方法详解 实现非常简单首先你要在你的项目里引用两个dll:actionlessform.dll.urlrewriter.dll,真正实现重写的是 ...
- C# winform窗体间传值(使用委托或事件)
窗体间传值 今天得空,刚好看到网上好多人再找winform窗体间传值的问题,由于昨天项目的优化的感觉不错,就写了个C# winform窗体间传值的demo,希望能给需要的人的带来帮助: 工程的源代码地 ...
- 【转】WinForm窗体显示和窗体间传值
以前对WinForm窗体显示和窗体间传值了解不是很清楚 最近做了一些WinForm项目,把用到的相关知识整理如下 A.WinForm中窗体显示 显示窗体可以有以下2种方法: Form.ShowDial ...
- C#利用事件与委托进行窗体间传值简单小例子
本篇博客是利用C#委托与事件进行窗体间传值的简单小例子 委托与事件的详细解释大家可以参照张子阳的博客: http://www.tracefact.net/CSharp-Programming/Dele ...
- ASP.NET页面间传值的几种方式
ASP.NET页面间传值的几种方式 1.使用QueryString 使用QuerySting在页面间传递值已经是一种很老的机制了,这种方法的主要优点是实现起来非常简单,然而它的缺点是传递的值是会显示在 ...
随机推荐
- uoj #118. 【UR #8】赴京赶考 水题
#118. [UR #8]赴京赶考 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://uoj.ac/problem/118 Description ...
- HTML5 API——无刷新更新地址 history.pushState/replaceState 方法
尽 管是上面讲到的<JavaScript高级程序设计>(第二版)中提到,BOM中的location.path/query…… (window.location)在通过JavaScript更 ...
- 剑指 offer set 1 二维数组中查找
总结 1. 二维数组搜索题遇到两个了, 一个是 Leetcode 上 search in 2D matrix. 那道题比较简单, 因为下一行的所有元素大于上一行的. 这道题对二维矩阵的要求比较松, 起 ...
- shell导出和导入redis
1.导出redis #!/bin/bash REDIS_HOST=localhost REDIS_PORT=6379 REDIS_DB=1 KEYNAME=redis:hash:* KEYFILE=k ...
- 配置Sublime Text 3的Python开发环境
最近的项目是用Python开发自动化测试脚本的,所以使用Python比较多.我用的编辑器是Sublime Text3. Sublime Text 3是一个轻量级的跨平台文字编辑器,一经面世便被认为是一 ...
- LeetCode25 Reverse Nodes in k-Group
题意: Given a linked list, reverse the nodes of a linked list k at a time and return its modified list ...
- 运用Real Spy Monitor监控网络
Real Spy Monitor是一个监测互联网和个人电脑,以保障其安全的软件.包括键盘敲击.网页站点.视窗开关.程序执行.屏幕扫描以及文件的出入等都是其监控的对象. 1.添加使用密码 在使用Real ...
- CSS3: border-radius边框圆角详解
border-radius 基本语法: border-radius : none | <length>{1,4} [/ <length>{1,4} ]? 取值范围: <l ...
- 【阿里云产品公测】一句话告诉你什么样的人该使用ACE,如何使用ACE
作者:阿里云用户小鸡咕咕 首先回应标题,这一句话就是:看完这篇帖子你就知道了. 前言 写在文章之前,我想先阐述一下写这篇文章的意义.可能大伙就要说了,写这篇文章不就是为了200的代金券吗?错, ...
- Precompile Prefix file(.pch文件)
参考资料: http://blog.csdn.net/lwjok2007/article/details/46385595 http://www.tuicool.com/articles/beURbe ...