开发者

using a masterpage's namespace from content page

Can i use namespace which is imported on masterpage ?

i can import and use namespace on masterpage like that..

<%@ Import Namespace="utl=portal.lib.SnkUtilities" %>

and on markup;

<a href='<%= "/" + utl.getSomeString() + "/cart.aspx" %>'>

but if want to use same namespace on a contentpage, i have to import same namespace on content second time as foll开发者_JAVA技巧ows:

    <%@ Page Title="" Language="C#" MasterPageFile="~/Master" AutoEventWireup="true" CodeBehind="Account.aspx.cs" Inherits="portal.secret.Account" %>
    <%@ Import Namespace="utl=portal.lib.SnkUtilities" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<%= utl.getAnotherString() %>
    </asp:Content>

Do you have any suggestions ?

Thanks in advance


You are thinking that the master page is read first, but in the page life cycle, the master page is read after the Page Request, so you have to include the namespace in every page. It first looks in the current page and if it does not find it at the compile time, you will get error.

When the page is fetched, the @ Page directive is read. If the directive references a master page, the master page is read as well. If this is the first time the pages have been requested, both pages are compiled.

Read from the End of the page Run-time Behavior of Master Pages

Note that the master page becomes a part of the content page. In effect, the master page acts in much the same way a user control acts — as a child of the content page and as a container within that page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜