understanding inline code <%...%>?

Posted on 2005-02-24
Medium Priority
Last Modified: 2010-05-18
What components can be accessed within a code rendering block (<%...%>)?

When an aspx file is loaded into an assembly, how is this code added to the Page instance.


    [Where does the code here go?  What does it have access to?  Is this code added to somewhat of an entry point function like a "void main(args){...}" such that execute functions of associative objects]

Question by:Tertioptus
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3

Expert Comment

ID: 13417667
In asp.net, the code rendering block can contain only the executable statements, and you can not write the procedure/function inside it. Procedures/functions have to be written inside the <script....></script> blocks. asp.net does not support the page render functions i.e. function inside the <%...%>.

Expert Comment

ID: 13418253

Code rendering blocks are denoted with <% ... %> elements, allow you to custom-control content emission, and execute during the render phase of Web Forms page execution.
Code enclosed by <% ... %> is just executed, while expressions that include an equal sign, <%= ... %>, are evaluated and the result is emitted as content. Therefore <%="Hello World" %> renders the same thing as the C# code <% Response.Write("Hello World"); %>.

Important: Unlike ASP -- where functions could be declared within <% %> blocks -- all functions and global page variables must be declared in a <script runat=server> tag. Functions declared within <% %> blocks will now generate a syntax compile error
Server-side comments enable page developers to prevent server code (including server controls) and static content from executing or rendering. The following sample demonstrates how to block content from executing and being sent down to a client. Note that everything between <%-- and --%> is filtered out and only visible in the original server file, even though it contains other ASP.NET directives.

Search Web with "Web Forms Syntax Reference" so that you can find more information.

Hope this helps.


Expert Comment

ID: 13418272

Author Comment

ID: 13422961
yes, but what scope is the code in.  

I know that you can have iterative statments (for... to)  and access the Container class, but I'm not sure where access to these objects and methods are coming from.

Is the inline code more like javascript that has access to a few server side objects?

Accepted Solution

sriggumma earned 630 total points
ID: 13428482
All Protected and Public objects/methods of the Page are accesible within <% %>

The variables which are last updated, if any required, in Page_PreRender before they are used with in <%%>

So almost all Server side objects, except a few, can be used with inline code too.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question