zoukankan      html  css  js  c++  java
  • asp.net <% %>,<%# %>,<%= %>,<%$ %>区别大集合

    前台页面

       <div>
    <%--可以执行服务器代码,相当于在后台写代码,Render%>
    <%=取后台变量或方法值,只能绑定客户端控件,绑定服务器控件时后来必须调用databind方法,后台变量必须为public,protect,相当于后台事件onDatabind%>
    <%#数据绑定,针对服务器控件绑定,从数据库中取数据<%#Eval("pSex") %>可以调用后台方法,<%#Bind("pSex") %>不能
    <%$只能绑定到服务器控件的属性上 %>--%>
    <%
        int a = 2;
        int b = 3;
        int c = a + b;
        Response.Write(c);
    %>
    <hr />
    文本
    <br />
    <%# aa %>
    <%=Display() %>
    服务器控件:
    <asp:TextBox runat="server" ID="b" Text='<%# aa %>' /><br />
    <asp:Label ID="bb" runat="server" Text='<%# Display() %>'></asp:Label>
    <hr />
    客户控件:<input type="text" name="name" id="a" value="<%= aa %>" /><br />
    <input type="text" name="name" id="aa" value="<%=Display() %>" />
    <hr />
    <asp:TextBox runat="server" ID="TextBox1" Text='<%$ConnectionStrings:pubs %>' />
    </div>

    后台页面

    protected string aa = "aaaaaaaaaaaaa";//or public
    protected void Page_Load(object sender, EventArgs e)
    {
        this.b.DataBind();
        this.DataBind();//绑定服务器控件必须用
    }

    public string Display()
    {
        return "bbbb";
    }

    WebConfig页面

      <connectionStrings>     <add name="pubs" connectionString="Server=.;datatbase=a;pwd=p;uid=u"/>     </connectionStrings>

    运行效果

  • 相关阅读:
    打印出1-10000之间的所有对称数(如121,1331,2442)
    代码块
    javascript判断数据类型
    块和内嵌
    xhtml+css基础知识2
    xhtml+css基础知识1
    清除浮动
    margin注意问题
    javascirpt 闭包
    css3 box-sizing属性
  • 原文地址:https://www.cnblogs.com/shenqiboy/p/3559266.html
Copyright © 2011-2022 走看看