ASP.NET中的代码可重用性 [英] code reusability in asp.net

查看:73
本文介绍了ASP.NET中的代码可重用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用继承和函数来消除代码中的冗余.现在,如何在没有公共访问说明符的情况下将一个aspx页面中的类的数据成员继承到另一页面?因为将其设为公开就像暴露了代码和数据一样

I use Inheritance and functions for removing redundancy in code.Now, How to inherit the data members of a class in one aspx page to another page without public access specifier?Because making it public is like exposing the code and data wont be encapsulated?

推荐答案

我不确定您要的是您想要的-但是您是对的,直接暴露字段是一种不好的做法-您应该将它们封装在属性中,然后将其公开.

但是我怀疑这对ASPX页面不会有太大帮助-因为在显示新页面时,上一页实际上不再存在,因此很难重新选择它.特性!我建议将页面值存储在Session中,并以这种方式从新页面访问它们:
I''m not sure that what you are asking for is exactly what you want - but you are right, it is bad practice to expose fields directly - you should encapsulate them in properties and make those public instead.

But I suspect that won''t help you too much with ASPX pages - since the previous page doesn''t really exist any more when the new page is displayed, it''s going to be difficult to pick up it''s properties! What I would suggest is storing the page values in the Session and accessing them from the new page that way: Session MSDN[^]


这篇关于ASP.NET中的代码可重用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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