<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site2.master.vb" Inherits="WLWeb.Site2" %>
<!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>
<script runat="server">
Protected Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnINMasterPage.Click
lblINMasterPage.Text = "MasterPage Hello " & Now.Ticks.ToString()
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblINMasterPage" runat="server" Text="Label in Master Page"></asp:Label>
<br />
<asp:Button ID="btnINMasterPage" runat="server" Text="Button in Master Page" />
<br />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
File SiteA.aspx Code (VB.NET)
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site2.Master"
CodeBehind="Site2A.aspx.vb" Inherits="WLWeb.Site2A" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script runat="server">
Protected Sub btnINChildPage_Click(sender As Object, e As EventArgs) Handles btnINChildPage.Click
lblINChildPage.Text = "ChildPage Hello " & Now.Ticks.ToString()
End Sub
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="lblINChildPage" runat="server" Text="Label in Child page"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:Button ID="btnINChildPage" runat="server" Text="Button in Child page" />
</asp:Content>
Date :
2013-03-12 10:56:38
By :
ผ่านมา
No. 9
Guest
ตัวอย่างการเล่นกับ Event บน Master Page
File Site2.Master
Code (VB.NET)
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site2.master.vb" Inherits="WLWeb.Site2" %>
<!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>
<script runat="server">
Public Event btnINMasterPageClick As EventHandler
Protected Sub btnINMasterPage_Click(sender As Object, e As EventArgs) Handles btnINMasterPage.Click
lblINMasterPage.Text = "MasterPage Hello " & Now.Ticks.ToString()
RaiseEvent btnINMasterPageClick(sender, e)
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="lblINMasterPage" runat="server" Text="Label in Master Page"></asp:Label>
<br />
<asp:Button ID="btnINMasterPage" runat="server" Text="Button in Master Page" />
<br />
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
</html>
File Site2A.aspx
Code (VB.NET)
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site2.Master"
CodeBehind="Site2A.aspx.vb" Inherits="WLWeb.Site2A" %>
<%@ MasterType VirtualPath="~/Site2.Master"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
AddHandler Master.btnINMasterPageClick, AddressOf SetLabelText
End Sub
Private Sub SetLabelText()
Try
Dim x As Label = DirectCast(Master.FindControl("lblINMasterPage"), Label)
x.Text = x.Text & " and WOW Click from Child Page " & Now.Ticks.ToString()
Catch ex As Exception
'Ignore error.
End Try
End Sub
Protected Sub btnINChildPage_Click(sender As Object, e As EventArgs) Handles btnINChildPage.Click
lblINChildPage.Text = "ChildPage Hello " & Now.Ticks.ToString()
End Sub
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Label ID="lblINChildPage" runat="server" Text="Label in Child page"></asp:Label>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:Button ID="btnINChildPage" runat="server" Text="Button in Child page" />
</asp:Content>