简体   繁体   中英

Is there a problem using scriptlet tags for aspx page?

I have made an aspx page in which much of the content gets generated on the logic that I have written in scriptlet tags. For eg

<%
  foreach(var data in dataCollection)
  { 
    int i=0;
%>
   <div>Enter value : &nbsp; <input id="<%=i %>" type="text" /></div>

<% } %>

like this I have built the whole page based on the logic of how the data is coming from back and how the data is to be appropriately shown on the page.

So, is there an issue with having scriptlets in aspx page? Is there something like best practice which advises against the use of scriptlets in aspx page?

Thanks Saarthak

First of all "scriptlet" is a Java concept, isn't it? Every technology has its terminology and one of best practices is call things by their proper name.

This is inline server code.

About if there's some issue with that, certainly this isn't the recommended approach for ASP.NET, but for earlier classic ASP like 3.0 which share the name but ASP and ASP.NET are absolutely different things.

In ASP.NET, in any page there's a markup code (page declaration, control registration, standard XHTML client-side code and user and custom server controls).

Any logic, processing or anything handling client interaction and rendering must be placed in a System.Web.UI.Page derived class, usually called "code-behind" (for example, Default.aspx.cs).

ASP.NET enforces a total separation of markup and client-side scripting from server-side backend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM