ASP <%%>&<%#%>&<%=%>&<%@%>&<%$%> Usage Differences

Source: Internet
Author: User
Tags connectionstrings

1.<%%> used to bind background code

Such as:

<%

for (int i=0;i<100;i++)

{

Reaponse.write (i.ToString ());

}

%>

2.<%#%> is executed when the bound control DataBind () method is executed for data binding

such as: <% # Container.DataItem ("title")%>

3.<%=%> The variable or method used to bind the background with a return value, but at this time the variable name or method's access modifier is protected or public

such as:<%=name%> <%=getstr ()%>

4.<%@%> used to import a background namespace

such as: <%@ import namespace= "System.Data" >

5.<%$%> used to bind strings in Web. config (key-value pairs)

such as: <asp:textbox runat= "Server" id= "CC" text= "<%$ connectionstrings:pubs%>" ></asp:TextBox>

Web. config

<configuration>
<system.web>
<compilation debug= "True" targetframework= "4.0"/>
</system.web>
<connectionStrings>
<add name= "Pubs" connectionstring= "server=.; Database=pubs;uid=sa;pwd= "providername=" System.Data.SqlClient "/>
</connectionStrings>
</configuration>

6.DataBind, the data obtained, the system will be implicitly think of the string, how to convert to other types?

Databinder.eval_r (Container.DataItem, "type of conversion", "format") Note: format can not be =eval_r ("type of conversion") for this method

7.<%:%> for direct display of ViewData data in MVC mode

In the action in Eg:controller:

User myuser=new  User (); Myuser.link="<a> I am link </a>"; viewdata["model"]=myuser;

This is referred to in the corresponding. aspx:

Links: <%:((MvcAppFirst.Models.User) viewdata["model"]). Link%>

is displayed as text in the page:<a> I am a link </a>

If referenced with <%= ...%>, it is displayed as a hyperlink.

ASP <%%>&<%#%>&<%=%>&<%@%>&<%$%> Usage Differences

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.