从Razor以编程方式更改DNN中的页面标题 [英] Change Page Title in DNN Programatically from Razor

查看:70
本文介绍了从Razor以编程方式更改DNN中的页面标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多如何以编程方式更改标题的方法,但至少在Razor脚本中才得到无效的结果

I've searched a lot for "How to change the title programatically" and only got this result which doesn't work, at least in Razor scripts

DotNetNuke.Framework.CDefault tp = (DotNetNuke.Framework.CDefault)this.Page;
tp.Title = "New Title Here";

这在剃须刀宿主脚本中不起作用,是否有其他解决方案可将页面标题从剃刀宿主脚本?

This doesn't work in razor host scripts, is there any other solutions to change the page title from Razor host script ?

推荐答案

经过多次试验和合并其他代码,我找到了解决方案

After many trials and merging others codes, I've found the solution

使用此按钮将使您可以访问页面访问权限,因此您可以使用它进行任何操作,更改标题等。

Using this will give you access to the page access, so you can do whatever you want with it, changing title etc.

var pageObj = Context.CurrentHandler as Page;
pageObj.Title = "My New Title for the page";

此代码将提供对DNN页面的访问,因此您可以插入控件等。

And this code will give access to the DNN Page, So you can insert controls etc.

DotNetNuke.Framework.CDefault tp = (DotNetNuke.Framework.CDefault)Context.CurrentHandler;
tp.FindControl("Head").Controls.Add(NewControlObj);

这篇关于从Razor以编程方式更改DNN中的页面标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆