User control (ascx) and properties

前端 未结 6 2222
终归单人心
终归单人心 2020-12-29 04:53

The only way I\'ve found to persist property values within a user control is to use the ViewState.

public string Title {
        get { return Convert.ToStrin         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 05:54

    It's not too bad--that is pretty much exactly how the built-in controls work and generally will lead to expected behavior. Best bet is to just selectively disable ViewState when you don't need to persist these values across postbacks.

    You also might want to look into ControlState--it is a separate "bag" that people can't disable, and is used for stuff like the GridView where there are some things that one can't turn off via viewstate because it breaks the control.

提交回复
热议问题