asp.Net   发布时间:2022-04-07  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了asp.net – 如何在回发上保持变量大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个单独的页面(代码为.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,detailview或任何其他rad类型的对象,它自己仍然保留键值,我不想使用任何一个。

如何在intFilEID中保留值集,而不会在HTML中创建可能会被更改的内容。

[编辑]更改了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

解决方法

正如其他人所指出的,您可以将其存储在Session或ViewState中。如果是页面特定的,我喜欢将其存储在ViewState中而不是Session中,但是我不知道一个方法是否一般比其他方法更好。

在VB中,您将在ViewState中存储一个项目,如:

ViewState(key) = value

并检索它像:

value = ViewState(key)

大佬总结

以上是大佬教程为你收集整理的asp.net – 如何在回发上保持变量全部内容,希望文章能够帮你解决asp.net – 如何在回发上保持变量所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。