Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

understanding inline code <%...%>?

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]

  • 3
1 Solution
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 <%...%>.

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.

TertioptusAuthor Commented:
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?
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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now