Congratulations to all the winners of April 2013, they have won INR 3400 cash and INR 20147 worth prizes !
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 13797 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > ASP .Net inline tags ...
Dhiren.Kaunar@Gmail.Com

ASP .Net inline tags

 Code Snippet posted by: Dhiren.Kaunar@Gmail.Com | Posted on: 4/18/2012 | Category: ASP.NET Codes | Views: 514 | Status: [Member] | Points: 40 | Alert Moderator   


Inline tags are useful in-order to write inline codes in the ASP .Net view page (aspx/ascx) pages .

Now in MVC view pages are using inline tags for inline coding, because in MVC we do not have any code behind for the view page.

Please find out some below mentioned frequently inline tags .

1. Normal Inline Tag: <% .... %>

Exmaple :
<% if (User.IsInRole("admin")) { %>

You can see this
<% } else { %>
You are no admin !
<%} %>


2. Single Pieces of Info: <%= ... %>

Used for small chunks of information, usually from objects and single pieces of information like a single string or int variable:

Example :

The Date is now <%= DateTime.Now.ToShortDateString() %>

The value of string1 is <%= string1 %>


*Note: <%= is the equivalent of Response.Write()

3. Binding Expression Tag : <%# .. %>
This tag is used to Binding Expressions, such as Eval and Bind, most often found in data controls
like GridView, Repeater, etc.:


Exmaple :

<asp:Repeater ID="rptMeetings" DataSourceID="meetings" 

runat="server">
<ItemTemplate>
<%# Eval("MeetingName")%>
</ItemTemplate>
</asp:Repeater>


4. Expressions (not code) often DataSources: <%$.%>

Exmaple :

<asp:SqlDataSource ID="party" runat="server" 

ConnectionString="<%$ ConnectionStrings:letsParty %>"
SelectCommand="SELECT * FROM [Employee]" />


5. Directive Tags <%@.%>
Directive Syntax - often at top of page for registering controls and page declaration

Exmaple :
<%@ Page Language="C#" 

MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" Title="Untitled Page" %>
<%@ Register TagPrefix="wp" Namespace="CustomWebParts" %>



6. Server side comment Tag : <%--.--%>

This is a server side comment, stuff you don't want anyone without code access to see:

Example :
<asp:Label ID="lblAwesome" runat="server"/>

<%-- sometimes end users make me angry --%>

<asp:LinkButton ID="lbEdit" Text="Edit"
OnClick="Edit_Click" runat="server" />


7. <%: ... %> This tag is identical to the "<%= ... %>" tag except that it
auto-html-encodes the value within the tag

Exmaple :
<%: Html.TextBox("FirstName") %> // This will dispaly a text box with ID='FirstName'


Thanks & Rgards,
Dhiren Kumar Kaunar
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/18/2013 4:18:38 AM