Quantcast convert asp.net page to user control

convert asp.net page to user control

by Neon Quach 31. January 2010 00:04

Nếu bạn muốn reuse lại các asp.net page bằng cách chuyển đổi chúng thành các user control, sau đó add chúng vào page để sử dụng thì các bước sau đây sẻ giúp bạn hòan thành việc đó.

Giả sử bạn có 1 asp.net page like this:

Đầu tiên chúng ta rename chúng lại thành ví dụ: default.aspx -> default.ascx, remove các thẻ: html, head, body, form, DOCTYPE. Sau đó đổi directive Page -> Control, remove tất cả các thuộc tính trên @Control directive trừ: Language, AutoEventWireup, CodeFile, Inherits.

Chuyển sang code behine chuyển thành kế thừa từ UserControl thay vì Page như hình sau:

Xong giờ có thể add user control này vào web form.

Reference

Tags: , , ,


Categories: asp.net | c# | vb.net

blog comments powered by Disqus

About me

I'm  currently employed as Software developer at devinition.com and also a Microsoft Certified Technology Specialist (MCTS), Microsoft Certified Professional Developer (MCPD) in Net Framework 2.0 and 3.5: Web Applications and MCTS .NET Framework 3.5, ADO.NET Applications

Powered by BlogEngine.NET 2.5.0.5 - Eco Theme by n3o Web Designers