2014年8月15日 星期五

WebUserControl MasterPage Page 取得控件

Master
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="DefaultSite.master.cs" Inherits="Debo.DefaultSite" %>

<%@ Register TagPrefix="TreeTool" TagName="tree" Src="~/UserTool/front/MenuTreeView.ascx" %>

<%@ Register TagPrefix="GoHomeBtn" TagName="GHB" Src="~/UserTool/front/GoHomeLinkButton.ascx" %>

<!DOCTYPE html>


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>網頁後台管理系統</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <link href="css/MainCss.less" rel="stylesheet" />

    <script src="Scripts/jquery-2.0.3.min.js"></script>

    <asp:ContentPlaceHolder ID="script" runat="server">

    </asp:ContentPlaceHolder>

</head>

<body>

    <form runat="server">

<div id="header">

   
 <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/_thumbs/Images/front/logo.png" PostBackUrl="~/index.aspx" 
/>

    

</div>

        <table style="margin:20px;">

            <tr>

                <td>

                    <TreeTool:tree ID="Tree1" runat="server"></TreeTool:tree>

                </td>

                <td valign="top" style="margin:0px 50px; position:absolute; width:auto;">

                    <GoHomeBtn:GHB ID="GHB1" runat="server"></GoHomeBtn:GHB>

                    <asp:ContentPlaceHolder ID="ContentMain" runat="server"></asp:ContentPlaceHolder>

                </td>

            </tr>

        </table>

        </form>

</body>

</html>


Page (News.aspx.cs)

        protected void Page_Load(object sender, EventArgs e)

        {

            Label lb = (Label)Page.Master.FindControl("GHB1").FindControl("GlobalLab");

            lb.Text = "新聞訊息";



            if (Request.QueryString["NewsID"] != null || Request.QueryString["Action"] != null)

            {

               

                NewsPlace.Controls.Add(this.LoadControl("~/UserTool/NewsFolder/newsedit.ascx"));

            }

            else

            {

                NewsPlace.Controls.Add(this.LoadControl("~/UserTool/NewsFolder/news.ascx"));

            }

        }


WebUserControl

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="GoHomeLinkButton.ascx.cs" Inherits="Debo.UserTool.GoHomeLinkButton" %>

<asp:LinkButton ID="GoHome" runat="server" Font-Underline="False" Font-Names="微軟正黑體" Font-Size="Small" ForeColor="Black">回首頁</asp:LinkButton>

<br/>

<asp:label ID="label1" runat="server" Font-Names="微軟正黑體" Font-Size="Small">當前位置: </asp:label><asp:LinkButton ID="Address" runat="server" Font-Names="微軟正黑體" Font-Size="Small" ForeColor="Black">網站管理中心--</asp:LinkButton><asp:Label ID="GlobalLab" runat="server" Text=""  Font-Names="微軟正黑體" Font-Size="Small" ></asp:Label>

<hr />

沒有留言:

張貼留言