选择显示字体大小

asp.net 2.0中动态修改页面标题

在老外的站上看到解决的好方法,故简单编译之:
在一个asp.net 的应用中,经常要动态修改页面的标题,一个典型的例子就是,在一个页面导航的控件中,希望用户点选哪一个连接,在页面的title里就显示相关的内容,举个例子,比如一个网站,有如下的网站架构:
有图书分类,下面再有中国图书,外国图书分类,则一般可以用树形或者asp.net 2.0的新增加的导航栏控件
(sitemap),来实现,比如

图书--->中国图书;
图书---->外国图书
等,而如果这个时候,能在页面的<title>部分,也能显示比如"图书-->中国图书"这样,那就更加直观明显了,
asp.net 2.0中,我们可以使用<head>部分的服务端控件来实现了,首先,要添加标记
<head runat="server">

然后可以在page_load事件中,以如下形式改边其title的内容了,如
page.header.title = "the current time is: " & datetime.now.tostring()
,也可以简单写成page.title.

然后,我们可以通过这样的办法,将其于sitemap控件结合了,实现方法如下:

const default_unnamed_page_title as string = "untitled page"
    const default_page_title as string = "welcome to my website!!"


    protected sub page_load(byval sender as object, byval e as system.eventargs) handles me.load
        'set the page's title, if needed
        if string.isnullorempty(page.title) orelse page.title = default_unnamed_page_title then
            if sitemap.currentnode is nothing then
                page.title = default_page_title
            else
                page.title = getpagetitlebasedonsitenavigation()

                'can also use the following if you'd rather
                'page.title = getpagetitlebasedonsitenavigationusingrecursion(sitemap.currentnode)
            end if
        end if
    end sub

    private function getpagetitlebasedonsitenavigation() as string
        if sitemap.currentnode is nothing then
            throw new argumentexception("currentnode cannot be nothing")
        end if

        'we are visiting a page defined in the site map - build up the page title
        'based on the site map node's place in the hierarchy

        dim output as string = string.empty
        dim currentnode as sitemapnode = sitemap.currentnode

        while currentnode isnot nothing
            if output.length > 0 then


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons