|
|
Copyright © 2003-2009 By Suthep Sangvirotjanaphat |
|
|
|
Mobile: 089-967-2200, 081-915-7816 Phone: 0-2992-4877 Fax: 0-2992-4878 Fast Contact Us |
GreatFriends.Biz Community |
Custom Search
|

<%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits="MasterPage" %>
<!
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></title> <asp:ContentPlaceHolder id="head" runat="server"> </asp:ContentPlaceHolder></
head><
body> <form id="form1" runat="server"> <div> <asp:Button ID="btnAdd" runat="server" Text="Add" /> <asp:Button ID="btnEdit" runat="server" Text="Edit" /> <asp:Button ID="btnDelete" runat="server" Text="Delete" /> <asp:Button ID="btnPrint" runat="server" Text="Print" /> <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </form></
body></
html>
--================== Masterpage.master.vb===================
Partial Class MasterPage
Inherits System.Web.UI.MasterPage
'-- สร้าง Property เพื่อไว้สำหรับ Ref ที่ Child
Public Property ctrlbtnAdd() As Button
Get
Return btnAdd End Get Set(ByVal value As Button)btnAdd = value
End Set End Property Public Property ctrlbtnEdit() As Button Get Return btnEdit End Get Set(ByVal value As Button)btnEdit = value
End Set End Property Public Property ctrlbtnDelete() As Button Get Return btnDelete End Get Set(ByVal value As Button)btnDelete = value
End Set End Property Public Property ctrlbtnPrint() As Button Get Return btnPrint End Get Set(ByVal value As Button)btnPrint = value
End Set End PropertyEnd
Class
--====================== Default.aspx สร้างหน้าตัวอย่าง Ref MasterPage
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></
asp:Content><
asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><
table style="font-family: Tahoma; font-size: medium; background-color: #FFFFFF; padding: inherit; margin: auto" width="100%"><
tr><td > <asp:Label ID="lblText" runat="server" Text=""></asp:Label> </td></tr></
table></
asp:Content>
'=============== Default.aspx.vb
Partial Class _Default
Inherits System.Web.UI.Page
Dim m As MasterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
'---- Get MasterPage และใช้ Property ได้เลยครับ
m = CType(Page.Master, MasterPage)
m.ctrlbtnAdd.Text = "เพิ่มรายการ"
m.ctrlbtnEdit.Enabled =
False AddHandler m.ctrlbtnPrint.Click, AddressOf btnPrint_Click End Sub Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Me.lblText.Text = "Print" End SubEnd
Class
ผลลัพธ์ที่ได้

|
|
mr.l |
วันที่ส่ง: 23 พ.ค. 52 17:02 GMT+7 วันที่ปรับล่าสุด: 25 พ.ค. 52 23:51 GMT+7 |

|
|
Ixus |
วันที่ส่ง: 23 พ.ค. 52 21:25 GMT+7 วันที่ปรับล่าสุด: 23 พ.ค. 52 21:25 GMT+7 |
ขอบคุณ mr.l นะครับ จะนำแนวทางนี้ไปต่อยอดอีกเยอะ ๆ เลยครับ
|
|
nuttanun4u |
วันที่ส่ง: 23 พ.ค. 52 21:33 GMT+7 วันที่ปรับล่าสุด: 23 พ.ค. 52 21:33 GMT+7 |

|
|
nano |
วันที่ส่ง: 25 พ.ค. 52 07:57 GMT+7 วันที่ปรับล่าสุด: 25 พ.ค. 52 07:57 GMT+7 |
เยี่ยมเลยครับ thank you หลายๆ ครับ|
|
nas |
วันที่ส่ง: 25 พ.ค. 52 09:43 GMT+7 วันที่ปรับล่าสุด: 25 พ.ค. 52 09:43 GMT+7 |
|
|
surrealist |
วันที่ส่ง: 25 พ.ค. 52 10:00 GMT+7 วันที่ปรับล่าสุด: 25 พ.ค. 52 10:00 GMT+7 |
<%@ MasterType VirtualPath="~/MasterPage.master"%>
'Dim m As MasterPage
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init ' m = CType(Page.Master, MasterPage)Master.ctrlbtnAdd.Text =
"เพิ่มรายการ"Master.ctrlbtnEdit.Enabled =
False AddHandler Master.ctrlbtnPrint.Click, AddressOf btnPrint_Click End Sub|
|
mr.l |
วันที่ส่ง: 25 พ.ค. 52 22:59 GMT+7 วันที่ปรับล่าสุด: 25 พ.ค. 52 22:59 GMT+7 |
Public
Interface IMasterPageProperties Property CtrlbtnAdd() As Button Property CtrlbtnEdit() As Button Property CtrlbtnDelete() As Button Property CtrlbtnPrint() As ButtonEnd
InterfacePartial Public Class MasterPage
Inherits System.Web.UI.MasterPage
Implements IMasterPageProperties
Public Property ctrlbtnAdd() As Button Implements IMasterPageProperties.CtrlbtnAdd
Get
Return btnAdd End Get Set(ByVal value As Button)btnAdd = value
End Set End Property Public Property ctrlbtnEdit() As Button Implements IMasterPageProperties.CtrlbtnEdit Get Return btnEdit End Get Set(ByVal value As Button)btnEdit = value
End Set End Property Public Property ctrlbtnDelete() As Button Implements IMasterPageProperties.CtrlbtnDelete Get Return btnDelete End Get Set(ByVal value As Button)btnDelete = value
End Set End Property Public Property ctrlbtnPrint() As Button Implements IMasterPageProperties.CtrlbtnPrint Get Return btnPrint End Get Set(ByVal value As Button)btnPrint = value
End Set End PropertyEnd
Class<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"></
asp:Content><
asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"></
asp:Content>Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
MasterPageFile = "~/MasterPage.master"
End Sub Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init' Case Properties
Dim [property] As IMasterPageProperties = TryCast(Page.Master, IMasterPageProperties)
If [property] IsNot Nothing Then
[property].CtrlbtnAdd.Text =
"เพิ่มรายการ"[property].CtrlbtnEdit.Enabled =
False AddHandler [property].CtrlbtnPrint.Click, AddressOf btnPrint_Click End If End Sub Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) End SubEnd
Class
' คร่าว ๆ ตัวอย่าง Implement Interface ครับ ผิดพลาด หรือ สงสัยประการใด Post ต่อด้านล่าง เลยนะค้าบ 
|
|
mr.l |
วันที่ส่ง: 25 พ.ค. 52 23:51 GMT+7 วันที่ปรับล่าสุด: 25 พ.ค. 52 23:51 GMT+7 |
|
เรียน .NET/OOAD กับ อ.สุเทพ (surrealist) Microsoft Most Valuable Professional (MVP): |
![]() ลงทะเบียนเรียน |