asp.net – 如何在回发上保持变量
发布时间:2020-12-16 00:47:33 所属栏目: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 – System.Security.SecurityException?
- asp.net-mvc – ASP.Net WebAPI区域支持
- ASP.Net分层应用程序 – 在层之间共享实体数据模
- asp.net-mvc – 如何将MEF与ASP.NET MVC 4和ASP.
- asp.net下创建、查询、修改带名称空间的 XML 文件
- asp.net – Request.Url.AbsoluteUri和重写的URL
- asp.net – 如何从ASP Web服务的JSON响应中删除d
- 模板 – ASP.NET MVC 2:如何为集合中的每个项调
- asp.net – 为什么我的jQuery UI datepicker在初
- asp.net – 服务器端声明缓存与Owin身份验证
热点阅读