Talking about the use of <%%>,<%=%>,<%#%><%$%> in ASP.

Source: Internet
Author: User
Learning without thinking is reckless, thinking without learning is dangerous, one small step per day, a big step in success

Use of <%%>,<%=%>,<% #eval ("")%><%$%> in ASP.

Here's a look at the use of <%%>,<%=%>,><%#%><%$%> in ASP.

First, let's take a look at the use of <%%>

Only server controls and general controls are used in ASPX pages, and sometimes you want to write C # code on that page, you must use <%%>, and then write C # code in it, let's look at an example

<form id="Form1" runat="server">    <div>       <%           Response.Write ("hello,world");         %>     </div></form>

This will allow the code to be displayed on the page. The code is as

Let's keep looking at <%=%>.

This is used to transfer values from the background page to the foreground page, which is used in the foreground to invoke the background variables or parameters, the foreground code is as follows:

<form id="Form1" runat="server">     <div>    <%=name%>     </div> </form>

The background code is as follows:

 Public Partial class index:system.web.ui.page{    public  String name;     protected void Page_Load (object  sender, EventArgs e)    {          name"haha" ;    }}

Next, let's take a look at <%#%>

This is a data control binding display used, with a variety of display methods

1.<%# Eval ("field queried")%> for example

<asp:datalist id="DataList1"runat="Server"Datasourceid="SqlDataSource1"> <ItemTemplate>_id:<asp:label id="_idlabel"runat="Server"text='<%# Eval ("_id")%>'/> <br/>_name:<asp:label id="_namelabel"runat="Server"text='<%# Eval ("_name")%>'/> <br/>_sex:<asp:label id="_sexlabel"runat="Server"text='<%# Eval ("_sex")%>'/> <br/>_tel:<asp:label id="_tellabel"runat="Server"text='<%# Eval ("_tel")%>'/> <br/><br/> </ItemTemplate> </asp:DataList>

2,<% #Bind ("")%> data source bound control of the FormView data display and binding, the code is as follows

<asp:formview id="FormView1"runat="Server"Datasourceid="SqlDataSource1"> <EditItemTemplate>_id:<asp:label id="_idlabel1"runat="Server"text='<%# Eval ("_id")%>'/> <br/>_name:<asp:textbox id="_nametextbox"runat="Server"text='<%# Bind ("_name")%>'/> <br/>_sex:<asp:checkbox id="_sexcheckbox"runat="Server"Checked='<%# Bind ("_sex")%>'/> <br/>_tel:<asp:textbox id="_teltextbox"runat="Server"text='<%# Bind ("_tel")%>'/> <br/> <asp:linkbutton id="UpdateButton"runat="Server"causesvalidation="True"CommandName="Update"text="Update"/> &nbsp;<asp:linkbutton id="Updatecancelbutton"runat="Server"CausesValidation="False"Commandname="Cancel"text="Cancel"/> </EditItemTemplate> <InsertItemTemplate>_name:<asp:textbox id="_nametextbox"runat="Server"text='<%# Bind ("_name")%>'/> <br/>_sex:<asp:checkbox id="_sexcheckbox"runat="Server"Checked='<%# Bind ("_sex")%>'/> <br/>_tel:<asp:textbox id="_teltextbox"runat="Server"text='<%# Bind ("_tel")%>'/> <br/> <asp:linkbutton id="Insertbutton"runat="Server"causesvalidation="True"CommandName="Insert"text="Insert"/> &nbsp;<asp:linkbutton id="Insertcancelbutton"runat="Server"CausesValidation="False"Commandname="Cancel"text="Cancel"/> </InsertItemTemplate> <ItemTemplate>_id:<asp:label id="_idlabel"runat="Server"text='<%# Eval ("_id")%>'/> <br/>_name:<asp:label id="_namelabel"runat="Server"text='<%# Bind ("_name")%>'/> <br/>_sex:<asp:checkbox id="_sexcheckbox"runat="Server"Checked='<%# Bind ("_sex")%>'Enabled="false"/> <br/>_tel:<asp:label id="_tellabel"runat="Server"text='<%# Bind ("_tel")%>'/> <br/> </ItemTemplate> </asp:FormView>

Finally, let's take a look at the rarely used <%$%>

This code is rarely seen, but can be used when using multi-language transformations, that is, you must first establish global and local resources, and then configure the following code in the configuration file, and then invoke the configuration file. The code is as follows

Configuration file Code

configuration>  <appSettings>    <add key= "Connect" value= "Hello"/>  </appSettings>    <system.web>        <compilation debug= "false" targetframework= "4.0"/>    </system.web>  </configuration>

To configure the calling code

<form id="Form1"runat="Server"> <div> <%--<asp:label id="Label1"runat="Server"text="<%$ resources:age%>"></asp:Label>--%> <asp:literal id="Literal1"runat="Server"text="<%$ resources:default.aspx,name%>"/> <asp:literal id="Literal2"runat="Server"text="<%$ resources:default.aspx,age%>"/> <asp:label id="heh"runat="Server"text="<%$ appsettings:connect%>"></asp:Label> </div>

All code Download

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.