User control (ascx) and properties

前端 未结 6 2221
终归单人心
终归单人心 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:49

    Your problem is exactly what ViewState is for: To persist properties of a control across postbacks, so your solution is just fine.

    You could save it in session, but that really just puts the burden on the server. Depending on the number of users you have, this could get really ugly really quickly.

    Also keep in mind that you have to do some housekeeping if you use session. For example, if you want to use your user control twice on the same page, you need to make sure that each control uses unique session variables.

提交回复
热议问题