User control's property loses value after a postback
User control's property loses value after a postback
All variables (and controls) are disposed at the end of the page's lifecycle. So you need a way to persist your variable, e.g. in the ViewState
.
public int DepartmentID
{
get {
if (ViewState["departmentID"] == null)
return int.MinValue;
else
return (int)ViewState["departmentID"];
}
set { ViewState["departmentID"] = value; }
}
The MSDN Magazine article "Nine Options for Managing Persistent User State in Your ASP.NET Application" is useful, but it's no longer viewable on the MSDN website. It's in the April 2003 edition, which you can download as a Windows Help file (.chm). (Don't forget to bring up the properties and unblock the "this was downloaded from the internet" thing, otherwise you can't view the articles.)
根据How to choose from Viewstate, SessionState, Cookies and Cache,对于配置文件中的数据,还是直接写在cache或者application级别比较好。不用考虑数据丢失的问题
User control's property loses value after a postback的更多相关文章
- Writing a Reusable Custom Control in WPF
In my previous post, I have already defined how you can inherit from an existing control and define ...
- Shape Control for .NET
Shape Control for .NET Yang Kok Wah, 23 Mar 2017 CPOL 4.83 (155 votes) Rate this: vote 1vote 2v ...
- [No000012E]WPF(6/7):概念绑定
WPF 的体系结构,标记扩展,依赖属性,逻辑树/可视化树,布局,转换等.今天,我们将讨论 WPF 最重要的一部分——绑定.WPF 带来了优秀的数据绑定方式,可以让我们绑定数据对象,这样每次对象发生更改 ...
- 微软原文翻译:适用于.Net Core的WPF数据绑定概述
原文链接,大部分是机器翻译,仅做了小部分修改.英.中文对照,看不懂的看英文. Data binding overview in WPF 2019/09/19 Data binding in Windo ...
- spring源码分析之<context:property-placeholder/>和<property-override/>
在一个spring xml配置文件中,NamespaceHandler是DefaultBeanDefinitionDocumentReader用来处理自定义命名空间的基础接口.其层次结构如下: < ...
- WPF's Style BasedOn
<Style x:Key="BasedStyle" BasedOn="{x:Null}" TargetType="{x:Type Control ...
- spring boot源码分析之SpringApplication
spring boot提供了sample程序,学习spring boot之前先跑一个最简单的示例: /* * Copyright 2012-2016 the original author or au ...
- WPFTookit Chart 入门
如何使用WPFToolKit Chart private void button1_Click(object sender, EventArgs e) { var s = new Series(); ...
- 关于 ant 不同渠道自动打包的笔记
必要的java.android.ant文件及循环打包用到的ant的jar 下载Ant(这里的Ant不是eclipse和android SDk里面自带的ant) 官方下载地址:http://a ...
随机推荐
- @encode关键字
@encode() 为了更好的互操作性,Objective-C 的数据类型,甚至自定义类型.函数或方法的元类型,都可以使用 ASCII 编码.@encode(aType) 可以返回该类型的 C 字符串 ...
- 前端每日实战:99# 视频演示如何用纯 CSS 创作一个过山车 loader
效果预览 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/KBxYZg/ 可交互视频 此视频是 ...
- LintCode之删除链表中的元素
题目描述 我的代码 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode n ...
- handler消息机制入门
handler消息机制入门 为什么要用handle? 我们在网络上读取图片信息时,是不能把耗时操作放在主线程里面的,当我们在子线程中获取到了图片的消息的时候,我们就需要把这个数据传给主线程. 而直接使 ...
- hdu 5517 Triple
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5517 ------------------------------------------------ ...
- Sublime Text 3 快捷键总结(Mac)
Command + Shift + L 光标同时定位多行 Command + Enter 在下一行插入新行.举个栗子:即使光标不在行尾,也能快速向下插入一行.
- LINUX shell脚本相关
调试脚本 测试脚本语法:bash -n file.sh 查看脚本每一步执行情况:bash -x file.sh 位置变量:$1,$2,... 特殊变量: %?:最后一个命令的执 ...
- 强哥新周报SQL
因为数据口径的更改,所以.强哥的SQL 比较好用.不会出麻烦. 总共有四个 日常记录下,好好看. -- 2019年4月核销新客 SELECT yzm2.consignee_phone AS `会员手机 ...
- 关于JS读取DOM对象(标签)的自定义属性
DOM对象对于js来说,是个很基础的元素,我们写js一般来说,都一定会对它进行操作.我们可以很方便地给它加上自定义的属性,比如: var test = document.getElementById( ...
- Git和Github操作
个人笔记和总结.如有错误欢迎指出https://github.com/zhaozehua0312/leran-gitAndgithub 内容已发布github上