在网页间传递参数的两种常用方法:Querystring和session。

我们在做ASP.NET的网页时,不可避免的要有到不同网页间参数的传递,在下面是在网页间传递参数的两种常用方法:这里并没有讨论参数传递的效率问题,我个人较喜欢用session传递,在使用结束后立即释放,感觉还是很方便的。

发送页的CODE:

< FONT style = " BACKGROUND-COLOR: #ffff00 " >      < FONT style = " BACKGROUND-COLOR: #ffff00 " >

ExpandedBlockStart.gif ContractedBlock.gif Private   Sub ImageButton1_Click() Sub ImageButton1_Click()Sub ImageButton1_Click()Sub ImageButton1_Click(ByVal sender As System.ObjectByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
InBlock.gif        
'通过Querystring传递参数或者session中
InBlock.gif

InBlock.gif        
'下面这一段是用QueryString来传输的
InBlock.gif
        'Dim Url As String
InBlock.gif
        'Url = "../search/LocalTemp.aspx.aspx?&Search=ok"
InBlock.gif
        'If txtEnterpriseName.Text <> "" Then
InBlock.gif
        '    Url = Url + "&E=" + txtEnterpriseName.Text
InBlock.gif
        'End If
InBlock.gif
        'If txtAddress.Text <> "" Then
InBlock.gif
        '    Url = Url + "&A=" + txtAddress.Text
InBlock.gif
        'End If
InBlock.gif
        'If DDLProvice.SelectedValue <> "选择省份" Then
InBlock.gif
        '    Url = Url + "&P=" + DDLProvice.SelectedValue
InBlock.gif
        'End If
InBlock.gif
        'If DDLCity.SelectedValue <> "选择城市" Then
InBlock.gif
        '    Url = Url + "$C=" + DDLCity.SelectedValue
InBlock.gif
        'End If
InBlock.gif
        'If Url = "../search/SingleDetailed.aspx?&Search=ok" Then
InBlock.gif
        '    '给出错误提示
InBlock.gif
        'End If
InBlock.gif
        'Response.Redirect(Url)
InBlock.gif

InBlock.gif        
' 下面使用session 传递
InBlock.gif
        Session("E"= txtEnterpriseName.Text
InBlock.gif        Session(
"A"= txtAddress.Text
InBlock.gif        Session(
"P"= DDLProvice.SelectedValue
InBlock.gif        Session(
"C"= DDLCity.SelectedValue
InBlock.gif        
'Server.Transfer()
InBlock.gif
        Response.Redirect("../search/LocalTemp.aspx")
ExpandedSubBlockEnd.gif    
End Sub

</FONT>  </FONT>


接受页的CODE:
None.gif < FONT style = " BACKGROUND-COLOR: #ffff00 " >< FONT style = " BACKGROUND-COLOR: #ffffff " >          </ FONT >< FONT style = " BACKGROUND-COLOR: #ffff00 " >  
None.gif
None.gif
ExpandedBlockStart.gifContractedBlock.gif
Private   Sub Page_Load() Sub Page_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load
InBlock.gif
InBlock.gif        
'Put user code to initialize the page here
InBlock.gif
        If Not IsPostBack Then
InBlock.gif          
'如果是Quesring是这样
InBlock.gif
          'Dim ENname as string = Request.QueryString["E"]
InBlock.gif
          Dim  EName As String
InBlock.gif          
Dim EAddress As String
InBlock.gif          
Dim EProvice As String
InBlock.gif          
Dim ECity As String
InBlock.gif            EName 
= Session("E").ToString
InBlock.gif            EAddress 
= Session("A").ToString
InBlock.gif            EProvice 
= Session("P").ToString
InBlock.gif            ECity 
= Session("C").ToString
InBlock.gif       
'----
InBlock.gif
       'your code 
InBlock.gif
       '-----
InBlock.gif
       'When you use finish
InBlock.gif
            Session.Remove("E")
InBlock.gif            Session.Remove(
"C")
InBlock.gif            Session.Remove(
"A")
InBlock.gif            Session.Remove(
"P")
InBlock.gif        
End If
ExpandedBlockEnd.gif    
End Sub
</ FONT ></ FONT >





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值