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 ...
随机推荐
- [TensorFlow 2] [Keras] fit()、fit_generator() 和 train_on_batch() 分析与应用
前言 是的,除了水报错文,我也来写点其他的.本文主要介绍Keras中以下三个函数的用法: fit()fit_generator()train_on_batch()当然,与上述三个函数相似的evalua ...
- 动态调试某个apk的smali代码,微信举例
本地环境: PC:windows 10,Intellij IDEA (android studio应该一样的) 手机:nexus5 8.1系统, 其他依赖:smalidea插件,xposed 插件 h ...
- CentOS下Java的安装与环境配置
网上的文章很多,但我还是不知道下次需要看谁的,或是给朋友推荐谁的,索性我都整理出来,方便下次需要的时候能很快的看到或是给朋友链接.两种安装方式:解压安装和包安装 1.安装前检查: 因为安 ...
- Digital Root 的推导
背景 在LeetCode上遇到这道题:Add Digits 大意是给一个数,把它各位数字相加得到一个数,如果这个数小于10就返回,不然继续 addDigits(这个相加得到的数). 题目很简单,但是如 ...
- Codeforces 1132D(二分答案+堆)
题面 传送门 分析 二分答案,考虑如何判定 可以用贪心的方法,每次找最快没电的电脑,在没电前1单位时间给它充电 正确性显然 实现上可以维护一个堆,存储每个电脑电用完的时刻,每次从堆顶取出最小的一个给它 ...
- redis设置密码的问题
<?php $redis = new redis( ); if( ! $redis -> connect( '192.168.73.128' , 6379 ) ){ exit( 'redi ...
- Python之字符串转换为日期、结合时区的日期操作
一.字符串转换为日期 方法一 s = '2019-01-20' print(datetime.strptime(s, '%Y-%m-%d')) # 2019-01-20 00:00:00 方法二 de ...
- js 屏蔽网页快捷键代码
<script> function KeyDown(){ //屏蔽鼠标右键.Ctrl+n.shift+F10.F5刷新.退格键 //alert("ASCII代码是:"+ ...
- 2018-10-8-如何安装-btsync
title author date CreateTime categories 如何安装 btsync lindexi 2018-10-8 9:15:6 +0800 2018-2-13 17:23:3 ...
- 拓展练习部分---打包压缩 及 RPM工具
目录 打包压缩部分 1.linux下常见的压缩包类型有哪些 rpm 工具部分 打包压缩部分 1.linux下常见的压缩包类型有哪些 .zip .gz 会删除源文件 .bz2 会删除源文件 .tar.g ...