zoukankan      html  css  js  c++  java
  • aspx页面中, <%= % > 与 <%# % > 的区别

    关于这个问题,在多数的 ASP.NET 的教材中,都提到了一些。 <%= % >与 <%# % >的区别在于:绑定时机不同, <%# % >是在控件调用DataBind函数的时候才被确定。对于 <%= % >,我想你应该不会陌生,在ASP时代,它就相当于 Response.Write。在ASP.NET时代也一样。暂时先不去理会教材中说的,也先把“绑定时机”放到一边。 <%= % >与 <%# % >的区别是:前者是输出,而后者是赋值!即:

     

         <%= "A" % > 相当于:Response.Write("A");

         <%# "A" % > 相当于:变量="A";

    先来看一个例子: 

    <html > 
    
    <body > 
    
    <asp:Button Text= <%# "Hello, the Internet!" % > RunAt="Server" ID="testButton" / > 
    
    </body > 
    
    </html > 


    这句话相当于赋值,把上面这个勾黑句子翻译成后台代码就是:testButton.Text="Hello, the Internet!";

    第二个例子: 

    <html > 
    
    <body > 
    
    <%= "Hello, the Internet!" % > 
    
    <%# "Hello, the Internet!" % > 
    
    </body > 
    
    </html > 


    <%= "Hello, the Internet!" % > 就相当于:Response.Write("Hello, the Internet!");

    那么第二个 <%# % >怎么解释呢?如果按照我“赋值”的说法,它把值赋给谁了呢?

    其实翻译成后台代码是这样的:(new System.Web.UI.LiteralControl()).Text="Hello, the Internet!";

  • 相关阅读:
    Android NDK Downloads
    Download Blackarch Linux
    Download Kali Linux
    Download ubuntu Linux
    cocos2D-X 常见49种Action
    win10 快速访问存在 2345Downloads 删除解决方案
    C++ 短信验证码/通知
    windows 登陆服务器
    使用路由器的虚拟服务器
    C++:查找字符串字串并替换
  • 原文地址:https://www.cnblogs.com/SFAN/p/3672623.html
Copyright © 2011-2022 走看看