各位老大,新年好!两个WebForm之间怎样传值? Happy New Years to you too!seePassing Values between ASP.NET Web Formshttp://www.dotnetbips.com/displayarticle.aspx?id=79 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1、server.Transfer2、session3、cookie4、url 最好不要在WEB FORMS 之间显式地传递值, WEB FORMS都是FORM, 一定要用POST. .NET是对事件编程的. 过多处理这些值的传递, 例如SESSION, COOKIE都不好. .NET是全新的WEB应用程序体系. 要注意结构上的设计. a.aspxsession["a"] = "abc";b.aspxstring a = session["a"].ToString();以上最常用,就是占用服务器资源。推荐使用url,可以对传递的参数值进行加密, sessionHappy New Year 2004! Session["abc"]="";赋值后,在别的页面可直接使用,Session有时间限制,可能会失效。URL传值:Page.RegisterStartupScript("set", "<script language=javascript>window.open('页面?参数名=参数值');</script>")URL只能是父窗口给子窗口传值。在子窗口中,通过Page.Request("参数名")获得传过来的值。 http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=9564 大吊车: “一定要用POST. .NET是对事件编程的. 过多处理这些值的传递“,“.NET是全新的WEB应用程序体系. 要注意结构上的设计.“这两句话能再详细点吗?谢谢! 新年快乐!1、server.Transfer2、session3、cookie4、url 用Session传值吧!送给你^_^,祝各位新年快乐! 转贴csdn:页面之间传递值方式1: 在接收页 的html代码里加上一行: <%@ Reference Page = "WebForm1.aspx" %> WebForm1 fp=(WebForm1)Context.Handler; this.TextBox1.Text=fp.name; //name 是第一页的public变量Context 提供对整个当前上下文(包括请求对象)的访问。您可以使用此类共享页之间的信息。 方式2:GET方式 在发送页 public int sum=0; int i =int.Parse(this.TextBox1.Text)*2; Server.Transfer("WebForm2.aspx?sum="+i); 接收页 this.TextBox1.Text=Request["sum"].ToString(); or this.TextBox1.Text=Request.Params["sum"].ToString(); this.TextBox1.Text=Request.QueryString["sum"];方法3:全局变量 发送页: Application["sum"]=this.TextBox1.Text; Server.Transfer("WebForm2.aspx"); 接收页: this.TextBox1.Text=(string)Application["sum"];Application实质上是整个虚拟目录中所有文件的集合,如果想在整个应用范围内使用某个变量值,Application对象将是最佳的选择在这里用Session[""]的方法雷同方法4: 发送页: 1.定义静态变量: public static string str=""; 2. str=this.TextBox1.Text; Server.Transfer("webform2.aspx"); 接收页: 1.引入第一页的命名空间:using WebApplication1; 2 this.TextBox1.Text=WebForm1.str;点击按钮弹出对话框 方法1:1,添加Hidden12,Page_Load()//Button1.Attributes.Add("onclick", "if(confirm('是否真的要删除?')){document.getElementById('Hidden1').value='你要返回的值'}else{return false;}");3,Button1_Click()//得到结果string s=this.Hidden1.Value;注意:如果Hidden1.Value的值总是为空,请检查Button1是否放在一个没有runat="server"的form中了,去掉form试试如果把Button1.Attributes.Add()方法放在Button1_Click()里,则先执行Button1_Click(),后执行onclick方法2:页面:<script language="javascript"> function getMessage() { var Flag=confirm("是否真的要删除?"); if (Flag) { alert("删除"); } else { alert("取消"); } } </script>代码:this.Button2.Attributes.Add("onclick","return getMessage();");文本框之间回车换位置 在<form 里加onkeydown='if(event.keyCode==13&&event.srcElement.type=="text")event.keyCode=9'<form id="Form1" onkeydown='if(event.keyCode==13&&event.srcElement.type=="text")event.keyCode=9' method="post" runat="server">一个页面只允许有一个form 带runat="server"带有按钮列的Table 使用 1。<asp:table id="Table2" style="BORDER-COLLAPSE: collapse" runat="server" Width="100%" GridLines="Both" BorderWidth="1px" BorderColor="DimGray"><asp:TableRow><asp:TableCell BackColor="#ddddd5" align="center" Text="单位"></asp:TableCell><asp:TableCell BackColor="#ddddd5" align="center" Text="上报日期"></asp:TableCell></asp:TableRow></asp:table>2。单元格鼠标移动效果<tr id="test" onmouseover="javascript:this.bgColor='#FFDDAA'" onmouseout="javascript:this.bgColor='#FFFFF5'" bgColor="#fffff5"><td vAlign="middle" align="center" colSpan="2">指定日规则列表</td></tr> 2。循环创建表格 for(int i=0;i<rs2.RecordCount;i++) { TableRow row=new TableRow(); TableCell cell1=new TableCell(); cell1.Text=rs2.Fields[1].Value.ToString(); row.Cells.Add(cell1); TableCell cell2=new TableCell(); cell2.Text=rs2.Fields[2].Value.ToString(); row.Cells.Add(cell2); TableCell cell3=new TableCell(); cell3.Text=rs2.Fields[5].Value.ToString(); row.Cells.Add(cell3); //创建操作按钮列 TableCell cell4=new TableCell(); System.Web.UI.WebControls.ImageButton im2=new System.Web.UI.WebControls.ImageButton (); im2.ImageUrl ="image/button_del.gif"; im2.BorderStyle=BorderStyle.None; im2.Click += new System.Web.UI.ImageClickEventHandler(this.im2_click); im2.ID=rs2.Fields[0].Value.ToString(); cell4.Controls.Add(im2); cell4.HorizontalAlign=HorizontalAlign.Center ; row.Cells.Add (cell4); this.Table1.Rows.Add(row); rs2.MoveNext(); }3。操作按钮列的事件: private void im2_click(object sender, System.Web.UI.ImageClickEventArgs e) { System.Web.UI.WebControls.ImageButton im2=(System.Web.UI.WebControls.ImageButton)sender; string id=im2.ID; string delsql="delete from M_System_WorkDayPerm where ID="+id; //建连接 ADODB.Connection Sybcn=new ADODB.Connection(); Sybcn.CursorLocation=ADODB.CursorLocationEnum.adUseClient; Sybcn.Open(Session["DBDBConnString"].ToString(),Session["DBDBUser"].ToString(),Session["DBDBPassWd"].ToString(),-1); object recordAffect; Sybcn.Execute(delsql,out recordAffect ,1); Sybcn.Close(); this.Page_Load(sender,e);//重新显示 } 1、server.Transfer2、session3、cookie4、url购物车,聊天室用到的技术都差不多,无非这几种 LiSDN(LOCK ON) 已經把最常用的方法說出來了1 我还只知道session呢呵呵学习学习 SessionApplicationUrl?... 不加任何访问修饰符的类作用域范围。。 关于visual2008中Gridview的问题,如何判断已选中某行 使用RemotingConfiguration 注册TCP信道 CPU占用好高 如何实例化 自定义类型的属性 关于中文字符串传递的问题 用C#实现文字的来回滚动? 在C#中一个记录集采用了两表连接的查询,请问怎样更新到数据库 怎么读取文件夹里的所有文件。 倒霉啊,老板要我做一个对PDF文件进行注释的程序,也就是说看到哪里,就可以当场在文件上标注并保存 用那个类可以产生一个临时文件? 窗口加载问题 怎样用C#在winform中实现对一个excel文件数据的读取?
2、session
3、cookie
4、url
string a = session["a"].ToString();以上最常用,就是占用服务器资源。推荐使用url,可以对传递的参数值进行加密,
赋值后,在别的页面可直接使用,Session有时间限制,可能会失效。URL传值:
Page.RegisterStartupScript("set", "<script language=javascript>window.open('页面?参数名=参数值');</script>")
URL只能是父窗口给子窗口传值。
在子窗口中,通过Page.Request("参数名")获得传过来的值。
谢谢!
2、session
3、cookie
4、url
送给你^_^,祝各位新年快乐!
页面之间传递值方式1:
在接收页 的html代码里加上一行: <%@ Reference Page = "WebForm1.aspx" %>
WebForm1 fp=(WebForm1)Context.Handler;
this.TextBox1.Text=fp.name; //name 是第一页的public变量
Context 提供对整个当前上下文(包括请求对象)的访问。您可以使用此类共享页之间的信息。 方式2:GET方式
在发送页
public int sum=0; int i =int.Parse(this.TextBox1.Text)*2; Server.Transfer("WebForm2.aspx?sum="+i); 接收页
this.TextBox1.Text=Request["sum"].ToString();
or this.TextBox1.Text=Request.Params["sum"].ToString();
this.TextBox1.Text=Request.QueryString["sum"];
方法3:全局变量 发送页:
Application["sum"]=this.TextBox1.Text;
Server.Transfer("WebForm2.aspx"); 接收页:
this.TextBox1.Text=(string)Application["sum"];Application实质上是整个虚拟目录中所有文件的集合,如果想在整个应用范围内使用某个变量值,Application对象将是最佳的选择在这里用Session[""]的方法雷同方法4: 发送页:
1.定义静态变量: public static string str="";
2. str=this.TextBox1.Text;
Server.Transfer("webform2.aspx");
接收页:
1.引入第一页的命名空间:using WebApplication1;
2 this.TextBox1.Text=WebForm1.str;
点击按钮弹出对话框 方法1:
1,添加Hidden12,Page_Load()//
Button1.Attributes.Add("onclick", "if(confirm('是否真的要删除?')){document.getElementById('Hidden1').value='你要返回的值'}else{return false;}");3,Button1_Click()//得到结果
string s=this.Hidden1.Value;注意:
如果Hidden1.Value的值总是为空,请检查Button1是否放在一个没有runat="server"的form中了,去掉form试试
如果把Button1.Attributes.Add()方法放在Button1_Click()里,则先执行Button1_Click(),后执行onclick
方法2:
页面:
<script language="javascript">
function getMessage()
{
var Flag=confirm("是否真的要删除?");
if (Flag)
{
alert("删除");
}
else
{
alert("取消");
}
}
</script>
代码:
this.Button2.Attributes.Add("onclick","return getMessage();");
文本框之间回车换位置
在<form 里加onkeydown='if(event.keyCode==13&&event.srcElement.type=="text")event.keyCode=9'<form id="Form1" onkeydown='if(event.keyCode==13&&event.srcElement.type=="text")event.keyCode=9' method="post" runat="server">
一个页面只允许有一个form 带runat="server"
带有按钮列的Table 使用
1。
<asp:table id="Table2" style="BORDER-COLLAPSE: collapse" runat="server" Width="100%" GridLines="Both" BorderWidth="1px" BorderColor="DimGray">
<asp:TableRow>
<asp:TableCell BackColor="#ddddd5" align="center" Text="单位"></asp:TableCell>
<asp:TableCell BackColor="#ddddd5" align="center" Text="上报日期"></asp:TableCell>
</asp:TableRow>
</asp:table>2。单元格鼠标移动效果<tr id="test" onmouseover="javascript:this.bgColor='#FFDDAA'" onmouseout="javascript:this.bgColor='#FFFFF5'" bgColor="#fffff5">
<td vAlign="middle" align="center" colSpan="2">指定日规则列表</td>
</tr>
2。循环创建表格 for(int i=0;i<rs2.RecordCount;i++)
{
TableRow row=new TableRow(); TableCell cell1=new TableCell();
cell1.Text=rs2.Fields[1].Value.ToString();
row.Cells.Add(cell1); TableCell cell2=new TableCell();
cell2.Text=rs2.Fields[2].Value.ToString();
row.Cells.Add(cell2);
TableCell cell3=new TableCell();
cell3.Text=rs2.Fields[5].Value.ToString();
row.Cells.Add(cell3); //创建操作按钮列
TableCell cell4=new TableCell();
System.Web.UI.WebControls.ImageButton im2=new System.Web.UI.WebControls.ImageButton ();
im2.ImageUrl ="image/button_del.gif";
im2.BorderStyle=BorderStyle.None;
im2.Click += new System.Web.UI.ImageClickEventHandler(this.im2_click);
im2.ID=rs2.Fields[0].Value.ToString();
cell4.Controls.Add(im2);
cell4.HorizontalAlign=HorizontalAlign.Center ;
row.Cells.Add (cell4); this.Table1.Rows.Add(row); rs2.MoveNext();
}3。操作按钮列的事件:
private void im2_click(object sender, System.Web.UI.ImageClickEventArgs e)
{
System.Web.UI.WebControls.ImageButton im2=(System.Web.UI.WebControls.ImageButton)sender;
string id=im2.ID;
string delsql="delete from M_System_WorkDayPerm where ID="+id; //建连接
ADODB.Connection Sybcn=new ADODB.Connection();
Sybcn.CursorLocation=ADODB.CursorLocationEnum.adUseClient;
Sybcn.Open(Session["DBDBConnString"].ToString(),Session["DBDBUser"].ToString(),Session["DBDBPassWd"].ToString(),-1); object recordAffect;
Sybcn.Execute(delsql,out recordAffect ,1);
Sybcn.Close();
this.Page_Load(sender,e);//重新显示
}
2、session
3、cookie
4、url购物车,聊天室用到的技术都差不多,无非这几种
Application
Url?
...