Meaning of <%%><%#%><%=%> represented in C #

Source: Internet
Author: User

1.<%%>

Server code can be executed, in layman's words can be written like the background code, such as:

1 <%2         int2; 3         int 3 ; 4         int C = a + b; 5         Response.Write (c); 6 %>

2.<%=%>
The expression for a service-side language can be a method with a return value, but the return value cannot be too large, note that there must be a return value . It can actually be seen as a binding.

Aspx.cs Code:

1  Public string  DISPLAYSTR ()// Note that there must be a return value here, or a run-time error of 2{3     return will occur " bbbb " ; 4 }

ASPX code:

1 <label id="label1"><%=displaystr ()%></label><br/> 2 <label id="label2" runat="server" ><%= Displaystr ()%></label>

3.<%#%>
This format is unique to ASP. XML, which is the syntax for control data binding. can only be used in data-bound controls. For example

3.1

Aspx.cs Code:

1 protected stringtext;2 protected voidPage_Load (Objectsender, EventArgs e)3 {4       if(!Page.IsPostBack)5       {6              This. Text ="aaaaaaaaaaaaa";7              This. Textbox1.databind ();//or this.              DataBind (); 8        }9}

ASPX code:

1<div>2Server Control:<asp:textbox id="TextBox1"runat="Server"text="<% #text%>"&GT;&LT;/ASP:TEXTBOX&GT;&LT;BR/><!--Server control-->3Client Control:<input type="text"Id="TextBox2"Value="<% #text%>"/><!--Client control-->4</div>

3.2 <% #Eval ("data column")%>

Primarily used to bind data columns that need to be changed, such as
Aspx.cs Code:

If the field value is 0 returns the male, otherwise returns the female

1  Public ObjectChangesex (Objectobj)2         {3             if(obj. ToString () = ="0")4             {5                 return "male";6             }7             Else 8             {9                 return "female";Ten             } One}

ASPX code:

Bind the Gender field to this binding to this, the gender value is variable

1 <% #ChangeSex (Eval (" gender "))%>=

3.3 <% #Bind ("data column")%>

A data column binding that is common in the GridView that does not require processing.
4 <%$%>

A common use of expressions is to set the connection string properties of a control (such as a SqlDataSource control) based on the value of the connection string stored in the Web. config file. For example, you might have the following SqlDataSource control that contains the connection string properties:

1 <asp:sqldatasource id="SqlDataSource1" runat="server " 2      selectcommand="select * FROM [Test]"3      connectionstring="  <%$ connectionstrings:testconnectionstring%>">4  </asp: Sqldatasource>

5. <%@%>
This syntax is primarily used for import, and the most familiar scenario is the one at the top of the ASPX page, such as the following code:

<% @Page .......%>

The line code is meant to define page-specific properties that are used by the ASP and the compiler, and can only be included in the ASPX page.

Meaning of <%%><%#%><%=%> represented in C #

Related Article

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.