用户控件(ASCX)和属性 [英] User control (ascx) and properties

查看:139
本文介绍了用户控件(ASCX)和属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现一个用户控件中坚持属性值的唯一方法就是使用ViewState的。

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.ToString(ViewState["Title"]); }
        set { ViewState["Title"] = value; }
    }

我不能说我虽然这个pssed真正IM $ P $,为更多的属性的用户控件具有更多的废话,你会在ViewState贴敷。有没有更好的方式来坚持属性?

I can't say I'm real impressed with this though, as the more properties a user control has the more crap you'll be sticking in the ViewState. Is there a better way to persist properties?

推荐答案

这要看情况。如果你需要的属性值将持续超越后回,那么你要么必须使用ViewState中或会话。由于这些控制在每个岗位重新创建回你真的不能保持这种状态,否则。

It depends. If you need to property values to be persisted beyond a post-back then you'll either have to use ViewState or Session. Since those controls are re-created on each post back you can't really maintain that state otherwise.

这篇关于用户控件(ASCX)和属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆