asp.net ,,,区别大集合

时间:2022-09-22 00:27:49

前台页面

   <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>

 

运行效果

asp.net ,,,区别大集合