Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the MasterPage function of imitating 2.0 in ASP.NET1.1

2025-03-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how ASP.NET1.1 realizes the MasterPage function of imitating 2.0. the content of the article is of high quality, so the editor shares it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

In asp.net 2.0, a masterpage function is provided, which makes it very convenient for us to complete the website with the same overall structure of the page, and when we modify the interface in the later stage, we only need to modify the masterpage, without the need to modify each interface, so it is very convenient for developers. In fact, similar technology can also be implemented in asp.net1.1.

Train of thought analysis

For websites that can use mastespanpage, most of its page structure is the same, such as the top and bottom are the same, but the content on the left and right is different. At this time, you might as well put the content on the left and right sides in the user control, and then dynamically load the user control according to the current access address, so that you can repair the website by modifying the content of the dynamically loaded user control or the framework of masterpage.

Realization process

First, get the address of the currently accessed file. The code is as follows:

/ / get the current access path sspaning sspanrequesturl = request.url.absolutepath.tosspaning (); / / get the current access file name and convert it to lowercase sspaning sspannowviewfile = sspanrequesturl.subsspaning ((sspanrequesturl.lastindexof (@ "/") + 1)) .trim () .tolower ()

Then click "add? add web user controls" to create three new user controls, named masterpage.ascx, head.ascx and foot.ascx, add a table with three rows and two columns in masterpage.ascx, then drag head.ascx and foot.ascx controls to masterpage.ascx, and add a placeholder control named hldleftconspanol and hldrightconspanol on the left and right sides. The results are as follows:

Head.ascx hldleftconspanol hldrightconspanol foot.ascx

At this point, just drag the masterpage.ascx to a specific page, such as index.aspx, and the top and bottom contents will be displayed after running. The next step is to determine which user controls are loaded dynamically to the left and right sides based on the address of the currently accessed file, which is done in masterpage.ascx.cs. The code is as follows:

/ / ASP.NET1.1switch (sspannowviewfile) {/ / if you are currently visiting the home page case "index.aspx": / / create an object of the user control class, and the class name is the same as the user control name conspanol_index_indexrightconspanol indexrightconspanol; / / load the user control indexrightconspanol = (conspanol_index_indexrightconspanol) page.loadconspanol ("conspanol_index_indexrightconspanol.ascx"); / / display the user control plhrightconspanol.conspanols.add (indexrightconspanol) in the placeholder control on the right Break; / / load member registration section case "register.aspx": conspanol_login_register register; register = (conspanol_login_register) page.loadconspanol ("conspanol_login_register.ascx"); plhrightconspanol.conspanols.add (register); break; default: indexrightconspanol = (conspanol_index_indexrightconspanol) page.loadconspanol ("conspanol_index_indexrightconspanol.ascx"); plhrightconspanol.conspanols.add (indexrightconspanol); break;}

After adding the above code, if the page visited is index.aspx, the contents of the conspanol_index_indexrightconspanol.ascx control will be loaded on the right side of the index.aspx page, and if you visit the register.aspx page, the contents of the conspanol_login_register.ascx control will be loaded on the right side.

This makes asp.net1.1 realize the function of masterpage.

On how ASP.NET1.1 to achieve imitation 2.0 MasterPage function to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report