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的更多相关文章

  1. 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 ...

  2. Shape Control for .NET

    Shape Control for .NET Yang Kok Wah, 23 Mar 2017 CPOL    4.83 (155 votes)   Rate this: vote 1vote 2v ...

  3. [No000012E]WPF(6/7):概念绑定

    WPF 的体系结构,标记扩展,依赖属性,逻辑树/可视化树,布局,转换等.今天,我们将讨论 WPF 最重要的一部分——绑定.WPF 带来了优秀的数据绑定方式,可以让我们绑定数据对象,这样每次对象发生更改 ...

  4. 微软原文翻译:适用于.Net Core的WPF数据绑定概述

    原文链接,大部分是机器翻译,仅做了小部分修改.英.中文对照,看不懂的看英文. Data binding overview in WPF 2019/09/19 Data binding in Windo ...

  5. spring源码分析之<context:property-placeholder/>和<property-override/>

    在一个spring xml配置文件中,NamespaceHandler是DefaultBeanDefinitionDocumentReader用来处理自定义命名空间的基础接口.其层次结构如下: < ...

  6. WPF's Style BasedOn

    <Style x:Key="BasedStyle" BasedOn="{x:Null}" TargetType="{x:Type Control ...

  7. spring boot源码分析之SpringApplication

    spring boot提供了sample程序,学习spring boot之前先跑一个最简单的示例: /* * Copyright 2012-2016 the original author or au ...

  8. WPFTookit Chart 入门

    如何使用WPFToolKit Chart private void button1_Click(object sender, EventArgs e) { var s = new Series(); ...

  9. 关于 ant 不同渠道自动打包的笔记

    必要的java.android.ant文件及循环打包用到的ant的jar 下载Ant(这里的Ant不是eclipse和android SDk里面自带的ant)      官方下载地址:http://a ...

随机推荐

  1. SelfCert wcf中 生成x5.09证书的工具

    http://blog.pluralsight.com/selfcert-create-a-self-signed-certificate-interactively-gui-or-programma ...

  2. English-Words with 'ir'

    hire thirty thirteen third sir birthday shirt stir circle dirty skirt affirm affirmation affirmable ...

  3. Python Django 编写一个简易的后台管理工具1-安装环境

    安装python环境 MAC 一般都会自带 Python2.x版本 的环境,你也可以在链接 https://www.python.org/downloads/mac-osx/ 上下载最新版安装. 安装 ...

  4. display:inline-block在IE6/Ie7和IE8中的区别

    在IE6.IE7中不识别display:inline-block属性,但使用inline-block属性在IE下会触发layout,从而使内联元素拥有了display:inline-block属性的表 ...

  5. linux shell assemble PDF文件

      daniel@daniel-mint ~/latex/linux/itext/daniel $ cat asm.sh header_start=0 header_len=15 xref_start ...

  6. pssh系列命令详解

    安装 pssh提供OpenSSH和相关工具的并行版本.包括pssh,pscp,prsync,pnuke和pslurp.该项目包括psshlib,可以在自定义应用程序中使用.pssh是python写的可 ...

  7. linux下部署springboot vue项目

    使用的工具是 XFTP5 XSHELL5 docker pull gmaslowski/jdk 拉取jdk docker images 查询下载的镜像ID (如:390b58b1be42) docke ...

  8. Learning OSG programing---osgwindows

    /* OpenSceneGraph example, osgwindows. * * Permission is hereby granted, free of charge, to any pers ...

  9. 转 什么是Mbps、Kbps、bps、kb、mb及其换算和区别

    Mbps 即 Milionbit pro second(百万位每秒): Kbps 即 Kilobit pro second(千位每秒): bps 即 bit pro second(位每秒): 速度单位 ...

  10. MySQL Workbench无法显示左侧的navigator,只显示Object info和Session

    问题描述:Mac版MySQL Workbench出现异常强制退出后,再次进入后左侧的navigator消失,左侧整个导航条消失了,只显示Object info和Session. 问题根源:MySQL ...