惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
S
Securelist
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tenable Blog
I
Intezer
G
GRAHAM CLULEY
Spread Privacy
Spread Privacy
T
Tor Project blog
V
Vulnerabilities – Threatpost
NISL@THU
NISL@THU
L
Lohrmann on Cybersecurity
Schneier on Security
Schneier on Security
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
S
Security @ Cisco Blogs
The Register - Security
The Register - Security
酷 壳 – CoolShell
酷 壳 – CoolShell
B
Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
L
LangChain Blog
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
MongoDB | Blog
MongoDB | Blog
小众软件
小众软件
The Hacker News
The Hacker News
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
Webroot Blog
Webroot Blog
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
H
Hackread – Cybersecurity News, Data Breaches, AI and More
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
V
Visual Studio Blog
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
T
The Exploit Database - CXSecurity.com
宝玉的分享
宝玉的分享
Vercel News
Vercel News
D
DataBreaches.Net
P
Palo Alto Networks Blog
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - yi

Rabbitmq的使用及Web监控工具使用 Fiddler的配置 轻松实现SQL Server与Access、Excel数据表间的导入导出 Sql server性能优化白皮书 索引的优化脚本 查找当前的登录用户 usp_who5脚本,查找当前的进程 linq to sql的性能和reader相比只是差一点点吗 锁与索引 一个数据访问层的小工具 转:对XML插入操作 - yi - 博客园 查看当前的连接和锁 对数据的分页再一次思考 关注商业价值 应用程序优化 关于异常处理的一点看法 骂的人多了,也成了真理 样式小记 - yi - 博客园 重命名你的数据库
不浪费自己的时间,同时也不浪费别人的时间 - yi - 博客园
yi · 2008-03-30 · via 博客园 - yi

    或许我很少在这里写东西,因为我要写一些对大家有用的东西,不想浪费自己写的时间,更不想浪费别人看的时间。

今天看了一编帖子,大概内容如下:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Main.master.cs" Inherits="Main" MasterPageFile="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>主母版页</title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div style="border-style: dashed; font-family: 宋体, Arial, Helvetica, sans-serif; font-size: xx-large; font-weight: 100; font-style: normal; font-variant: normal; text-transform: capitalize; color: #FF0000">主要的母版页!</div>
      <br />
      <div align="center"
                style="font-family: 宋体, Arial, Helvetica, sans-serif; font-size: large; font-weight: 400; font-style: italic">Hi!欢迎您使用ASP.NET3.5!<br />
          <asp:Button ID="Button1" runat="server"  Text="Button" />
            </div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
       
        </asp:ContentPlaceHolder>
        <div align="center" style="border-style: ridge">版权所有,违者必究! 浙江新能量科技有限公司2008</div>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class Main : System.Web.UI.MasterPage,IMasterData
{
    public int BtnCount
    {
        get
        {
            return this.ViewState["BtnCount"] == null ? 0 : Convert.ToInt32(this.ViewState["BtnCount"]);
        }
        set
        {
            this.ViewState["BtnCount"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.BtnCount++;
    }
}

其中IMasterData
接口的代码如下:

/// <summary>
///母版页的数据
/// </summary>
public interface IMasterData
{
    int BtnCount { get; set; }
}

方法一:
在内容页面中使用:

((Main)this.Page.Master).BtnCount;

此方法不推荐,灵活程度很低,万一哪天BtnCount或者Main更改了,或者是在多个母版页之中选择,这行代码就很危险。


方法二:
在内容页面中使用:
((IMasterData)this.Page.Master).BtnCount;推荐,定义一个接口,通过接口来调用要调用的成员,针对接口编程,好处不用我说了。

方法三:
在内容页面中使用:

this.Page.Master.GetType().GetProperty("BtnCount").GetValue(this.Page.Master, null)

这是一种相对灵活的方法,在编译的时候无法判断错误的方法,特殊情况下可以考虑使用此方法。

方法四:

override object SaveViewState()和override void LoadViewState(object savedState)

说的是,获取母亲的属性,这里我想说的是,是先有父母,还是先有儿子,如果先有父母,何谈变化,如果没有变化,方法二三四的执行效率是那一个高呢,这个大家应该很清楚。
是不是啥东西都需要变化呢,如果需要应对变化,省级、市级、县级的数据库难道就要设计很多张表吗?一些理论的东西只适应一定的范围,如果超出了这个范围就无从谈起了