作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了一个页面(带有 .vb 后面的代码)并创建了 Public intFileID As Integer
在页面加载中,我检查查询字符串并在可用时分配它或设置 intFileID = 0。
Public intFileID As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If Not Request.QueryString("fileid") Is Nothing Then
intFileID = CInt(Request.QueryString("fileid"))
End If
If intFileID > 0 Then
GetFile(intFileID)
End If
End If
End Sub
Private Sub GetFile()
'uses intFileID to retrieve the specific record from database and set's the various textbox.text
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
If Not Request.QueryString("fileid") Is Nothing Then
intFileID = CInt(Request.QueryString("fileid"))
End If
If intFileID > 0 Then
GetFile(intFileID)
End If
ViewState("intFileID") = intFileID
Else
intFileID = ViewState("intFileID")
End If
End Sub
最佳答案
正如其他人指出的那样,您可以将其存储在 Session 或 ViewState 中。如果它是特定于页面的,我喜欢将它存储在 ViewState 中而不是 Session 中,但我不知道一种方法是否通常比另一种方法更受欢迎。
在 VB 中,您将在 ViewState 中存储一个项目,例如:
ViewState(key) = value
value = ViewState(key)
关于asp.net - 如何在回发时保留变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/222999/
我是一名优秀的程序员,十分优秀!