【发布时间】:2010-09-18 09:21:43
【问题描述】:
我创建了一个页面(代码在 .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
提交按钮有一个单击事件,它根据 intFileID 变量的值插入或更新记录。我需要能够在回发时保持该值,以便一切正常工作。
页面只是在 SQL 数据库中插入或更新记录。我没有使用 gridview、formview、detailsview 或任何其他 rad 类型的对象,它们本身会保留键值,我不想使用它们中的任何一个。
如何保持 intFileID 中设置的值,而不在 HTML 中创建可能被更改的内容。
[EDIT] 将 Page_Load 更改为使用 ViewState 来持久化 intFileID 值
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
【问题讨论】: