跨网页公布技术

     以往做网页导航必须通过QueryString带参数,这种带参数方式有好多弊端,一来要传递的参数很多,你会觉得QueryString这样的手法很笨,二者因为传递的参数是固定的,倘若在目的端网页要动态访问不确定项目,或要读取不在预期内的项目必须回头修改添加传递的参数.而asp.net 2.0的跨网页公布新技术不是单纯传递参数,而是能够存取Page中所有控件,例如传递TextBox控件的长,宽,字号等等,这里QueryString所不能做到的.下面我写个例子说明如果使用跨网页公布技术.

在vs2005中新建两个WebForm,Source.aspx和Target.aspx

 Source.aspx

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="Source.aspx.cs" Inherits="Source"  %>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head  id ="Head1"  runat ="server" >
    
< title > 无标题页 </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >
        
< asp:TextBox  ID ="TextBox1"  runat ="server"  ForeColor ="Red" > Text in TextBox1 </ asp:TextBox >< asp:Button  ID ="Button1"
            runat
="server"  Text ="确定"  PostBackUrl ="~/Target.aspx"   />
    
</ div >
    
</ form >
</ body >
</ html >

Source.aspx.cs

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  Source : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{

    }

    
public System.Drawing.Color ForeColor
    
{
        
get
        
{
            
return TextBox1.ForeColor;
        }

    }

    
public String Text
    
{
        
get
        
{
            
return TextBox1.Text;
        }

    }

}

Target.aspx

 

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="Target.aspx.cs" Inherits="Target"  %>
<% @ PreviousPageType VirtualPath="~/Source.aspx"  %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

< html  xmlns ="http://www.w3.org/1999/xhtml"   >
< head  runat ="server" >
    
< title > 无标题页 </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >
    
< asp:Label  ID ="Label1"  runat ="server"  Text ="Label" ></ asp:Label >
    
</ div >
    
</ form >
</ body >
</ html >

Target.aspx.cs

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  Target : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        Label1.ForeColor 
= PreviousPage.ForeColor;
        Label1.Text 
= PreviousPage.Text;
    }

}

运行以后按确定你会看到Sorce.aspx页面TextBox1的Text和ForeColor都传递给了Target.aspx页面的Label1

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值