asp.net – 如何在回发上保持变量
发布时间:2020-05-23 14:55:42 所属栏目:asp.Net 来源:互联网
导读:我创建了一个单独的页面(代码为.vb),并创建了Public intFileID As Integer 在页面加载中,我检查查询字符串并将其分配(如果可用)或设置intFileID = 0。 Public intFileID As Integer = 0Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.
|
我创建了一个单独的页面(代码为.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 – 如何和在哪里调用Database.EnsureCreated和Data
- asp.net – Response.TrySkipIisCustomErrors不工作
- asp.net – 是果园还是Umbraco MVC?
- asp.net-mvc – 尝试将asp.net web发布到Azure时,Visual St
- .net – WebApi传输字节数组为空
- asp.net – 使用回发解析.Net页面
- asp.net-mvc – 401响应代码的json请求与ASP.NET MVC
- asp.net – IIS 7在一个服务器上引发web.config的“重复部分
- asp.net-web-api – HttpClient不报告从Web API返回的异常
- 压力测试ASP.Net应用程序
推荐文章
站长推荐
- asp.net-mvc-3 – 强制重新验证mvc3不显眼的远程
- asp.net – 为什么IIS中的Windows /集成身份验证
- ASP.Net MVC – 为什么要为favicon.ico创建一个控
- ASP.NET MVC4 WebAPI和Posting XML数据
- asp.net-mvc-3 – jQuery Mobile/MVC:使用Redir
- asp.net – 验证失败后如何防止页面跳转到顶部位
- asp.net-mvc – 十进制的最佳数据注释(18,2)
- 标签 – 如何使用像asp这样的Razor:Literal?
- Asp.net UserControl LoadControl问题
- asp.net-mvc – ELMAH – 使用自定义错误页面收集
热点阅读
