我们在做ASP.NET的网页时,不可避免的要有到不同网页间参数的传递,在下面是在网页间传递参数的两种常用方法:这里并没有讨论参数传递的效率问题,我个人较喜欢用session传递,在使用结束后立即释放,感觉还是很方便的。
发送页的CODE:
<FONT style="BACKGROUND-COLOR: #ffff00"> <FONT style="BACKGROUND-COLOR: #ffff00">
Private Sub ImageButton1_Click()Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
'通过Querystring传递参数或者session中
![]()
'下面这一段是用QueryString来传输的
'Dim Url As String
'Url = "../search/LocalTemp.aspx.aspx?&Search=ok"
'If txtEnterpriseName.Text <> "" Then
' Url = Url + "&E=" + txtEnterpriseName.Text
'End If
'If txtAddress.Text <> "" Then
' Url = Url + "&A=" + txtAddress.Text
'End If
'If DDLProvice.SelectedValue <> "选择省份" Then
' Url = Url + "&P=" + DDLProvice.SelectedValue
'End If
'If DDLCity.SelectedValue <> "选择城市" Then
' Url = Url + "$C=" + DDLCity.SelectedValue
'End If
'If Url = "../search/SingleDetailed.aspx?&Search=ok" Then
' '给出错误提示
'End If
'Response.Redirect(Url)
![]()
' 下面使用session 传递
Session("E") = txtEnterpriseName.Text
Session("A") = txtAddress.Text
Session("P") = DDLProvice.SelectedValue
Session("C") = DDLCity.SelectedValue
'Server.Transfer()
Response.Redirect("../search/LocalTemp.aspx")
End Sub
</FONT> </FONT>
接受页的CODE:
<FONT style="BACKGROUND-COLOR: #ffff00"><FONT style="BACKGROUND-COLOR: #ffffff"> </FONT><FONT style="BACKGROUND-COLOR: #ffff00">
![]()
![]()
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
![]()
'Put user code to initialize the page here
If Not IsPostBack Then
'如果是Quesring是这样
'Dim ENname as string = Request.QueryString["E"]
Dim EName As String
Dim EAddress As String
Dim EProvice As String
Dim ECity As String
EName = Session("E").ToString
EAddress = Session("A").ToString
EProvice = Session("P").ToString
ECity = Session("C").ToString
'----
'your code
'-----
'When you use finish
Session.Remove("E")
Session.Remove("C")
Session.Remove("A")
Session.Remove("P")
End If
End Sub</FONT></FONT>
发送页的CODE:
<FONT style="BACKGROUND-COLOR: #ffff00"> <FONT style="BACKGROUND-COLOR: #ffff00">
Private Sub ImageButton1_Click()Sub ImageButton1_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
'通过Querystring传递参数或者session中
'下面这一段是用QueryString来传输的
'Dim Url As String
'Url = "../search/LocalTemp.aspx.aspx?&Search=ok"
'If txtEnterpriseName.Text <> "" Then
' Url = Url + "&E=" + txtEnterpriseName.Text
'End If
'If txtAddress.Text <> "" Then
' Url = Url + "&A=" + txtAddress.Text
'End If
'If DDLProvice.SelectedValue <> "选择省份" Then
' Url = Url + "&P=" + DDLProvice.SelectedValue
'End If
'If DDLCity.SelectedValue <> "选择城市" Then
' Url = Url + "$C=" + DDLCity.SelectedValue
'End If
'If Url = "../search/SingleDetailed.aspx?&Search=ok" Then
' '给出错误提示
'End If
'Response.Redirect(Url)
' 下面使用session 传递
Session("E") = txtEnterpriseName.Text
Session("A") = txtAddress.Text
Session("P") = DDLProvice.SelectedValue
Session("C") = DDLCity.SelectedValue
'Server.Transfer()
Response.Redirect("../search/LocalTemp.aspx")
End Sub</FONT> </FONT>
接受页的CODE:
<FONT style="BACKGROUND-COLOR: #ffff00"><FONT style="BACKGROUND-COLOR: #ffffff"> </FONT><FONT style="BACKGROUND-COLOR: #ffff00"> 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
'如果是Quesring是这样
'Dim ENname as string = Request.QueryString["E"]
Dim EName As String
Dim EAddress As String
Dim EProvice As String
Dim ECity As String
EName = Session("E").ToString
EAddress = Session("A").ToString
EProvice = Session("P").ToString
ECity = Session("C").ToString
'----
'your code
'-----
'When you use finish
Session.Remove("E")
Session.Remove("C")
Session.Remove("A")
Session.Remove("P")
End If
End Sub</FONT></FONT>


浙公网安备 33010602011771号