I'm working with some designs in asp , I want to save the creation of x number of ASP pages, it is worth mentioning that I am working with
If seeing such or such div
depends on a dynamic event in the browser, it is ok to use javascript, but if not, it is recommended that you limit it directly on the server
@if (PasaTalCosa) {
@Html.Partial("Div1")
}
As you see in the example, you can also put each of the divs
in its own partial, for doubts you need to use it in different actions.
Creating elements from the server code of your .aspx page is very simple, in your .aspx.cs:
private void CrearItems()
{
// Crear elemento div genérico
HtmlGenericControl item = new HtmlGenericControl("div");
// Creamos los elementos de la lista de forma dinámica
foreach (var elemento in tuColeccion)
{
// Establecer atributos necesarios
// item.Attributes.Add("class", "item");
// item.Id
// item.InnerHtml
// etc...
// Añadir elemento div al elemento contenedor
contenedor.Controls.Add(item)
}
}
In your .aspx you only need to define a container control to which the <div>
will be added.
It can be an asp.net web server control:
<asp:Panel ID= "contenedor" runat = "server"></asp:Panel>
or, an html server control:
<div id="contenedor" class="contenedor" runat="server"></div>
What you need here is to make a SPA (Single Page Application). Have you seen Angular ??
You can see how this example works: link to get an idea.