將Web網頁轉化為使用者控制項

來源:互聯網
上載者:User

標籤:ar   sp   for   檔案   on   art   代碼   html   ad   

將Web網頁轉化成使用者控制項,需要進行以下操作:

1、在.asp(Web網頁的副檔名)檔案的HTML視圖中,刪除<html>、<head>、<body>以及<form>等標記。

2、將@Page指令修改為@Control,並將Codebehind屬性修改成以.ascx.cs為擴充的檔案。例如:

原Web網頁中的代碼如下:

<%@ Page Language="C#" AutoEventWireup="ture" CodeFile="Default.aspx.cs" Inherits="_Defualt"%>

需要修改為:

<%@ Control Language="C#" AutoEventWireup="ture" CodeFile="Default.aspx.cs" Inherits="_Defualt"%>

3、在後台代碼中,將public class 聲明的葉類刪除,改為使用者控制項的名稱,並且將System.Web.UI.Page改為System.Web.UI.UserControl。

例如:

public partial class _Default:System.Web.UI.Page

需要修改為:

public partial class _Default:System.Web.UI.UserControl

4、在“方案總管”視窗中,將檔案的副檔名從.aspc修改為.ascx,其代碼後置檔案會隨之改變,即從.aspx.cs改變為.ascx.cs。

將Web網頁轉化為使用者控制項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.