| |

VerySource

 Forgot password?
 Register
Search
View: 2042|Reply: 17

Have you ever made a website that dynamically loads the template page html front-end display content?

[Copy link]

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-12-17 14:00:01
| Show all posts |Read mode
Everyone help! Question: The home page is in the form of index.aspx, and then a static template page under the folder is called with code in the background, such as index.htm, which has {%title%}, or the function {%ShowArticleList(x,x,x) ,x,x,true,false,0,1,1,3,4)%} and so on, and then replace them, load them into index.aspx using the cache, and display them. If the template also has .net controls, also Loading the content of the control, the program has to judge, find the control, bind the content, etc. How to achieve this?
Everyone help!
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-17 19:45:01
| Show all posts
This kind of situation is generally realized by masterpage. Just specify the masterpage of the current page. In fact, the effect is the same as that of the template, but you don’t need to manage the things in the template page, you only need to replace some of them.
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-12-17 20:45:01
| Show all posts
What if it is static? masterpage will not work
Reply

Use magic Report

0

Threads

8

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-19 23:15:01
| Show all posts
Static pages are also possible, for example, you can access through dynamic pages:
http://www.xx.com/show.aspx?id=1001
You can make a class specifically to generate static pages, automatically access this dynamic address when generating, obtain the source code and save it as the static page you want to display, and call the static operation when adding or modifying content
The advantage is that you only need to re-staticize it once when changing the template, which is much more convenient
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-20 10:00:01
| Show all posts
Generally speaking, the under-entry development thinking is used, that is, the ASPX page is added to the HTML page
Reply

Use magic Report

0

Threads

8

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-20 12:00:01
| Show all posts
Use ASP.NET, and then realize through ExpressionBuilder, <%$%> is explained through ExpressionBuilder, for example, <%$ ConnectionStrings: MyConnection %> is explained by ConnectionStringsExpressionBuilder, similarly there are AppSettingsExpressionBuilder and so on. All you need to do is to write your own ExpressionBuilder and return the string you want to fill in in its GetCodeExpression method.
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Thailand

 Author| Post time: 2020-12-20 20:45:01
| Show all posts
The content of the template page index.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled page</title>
</head>
<body>
    <form id="form1">
    <div>
        wo ai ni a
        <%=title()%></div>
    </form>
</body>
</html>

Home Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default"%>
<%@ OutputCache Duration="180" VaryByParam="None" %>

Source file Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
    {
        string InForPath = "Templets/index.htm";
        string path = System.Web.HttpContext.Current.Server.MapPath(InForPath);
        StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);
        string line="";
        try
        {
            line = sr.ReadToEnd();
        }
        finally
        {
            sr.Close();
            sr.Dispose();
        }
        if(!Page.IsPostBack)
        {
            Page.Controls.Add(Page.ParseControl(line));
        }
    }
    public static string title()
    {
        string str = "wo shi ni de baobei";
        return str;
    }


The above simple example
The problem is that the function title cannot be executed, and runat="server" cannot be added, otherwise server-side hidden controls will appear
Everyone, see if there is any way?
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-20 23:00:01
| Show all posts
IIS add html .net framework mapping

RewriteUrl

Page cache

Almost the same effect
Reply

Use magic Report

1

Threads

7

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-12-21 04:15:01
| Show all posts
If the amount of data is large, the server will freeze
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-21 06:30:01
| Show all posts
Is to cyclically replace the tags in the target data
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list