1. What is the module title?
The title is defined in the official document developed by DNN Skin & Container, as shown in figure
In the HTML file of the corresponding iner package (DNN will "compile" the HTML to use the ascx file, basically replacing the [XXX] type label with the Control defined by DNN ), yes.
<TD background = "tile_body_top.jpg" align = "middle" noWrap> [SOLPARTACTIONS] </TD>
<TD background = "tile_body_top.jpg" align = "middle" width = "100%" nowrap> [TITLE] </TD>
<TD background = "tile_body_top.jpg" align = "middle" noWrap> [VISIBILITY] </TD>
<TD vAlign = "top" noWrap align = "right" width = "20" colspan = "2">
</TD>
2. How do I set the title?
The title is generally set when the module is added in management mode.
You can also modify the settings on the Setting page of the module.
However, sometimes we need to be able to dynamically modify the module title through the program.
3. How to access the title?
After exploration, you can access:
Label lbTitle = (Label) (this. ContainerControl. FindControl ("dnnTITLE"). Controls [0]);
LbTitle. Text = objBookItem. Title;
We know that this (module) is inherited from PortalModuleBase, and PortalModuleBase defines:
Public Control ContainerControl {get ;}
This is our container object.
It is just a common UserControl. It contains several controls, including dnn: the ID of the TITLE is "dnnTITLE", which can be found through FindControl.
<% @ Control language = "vb" CodeBehind = "~ /Admin/Containers/container. vb "AutoEventWireup =" false "Explicit =" True "Inherits =" DotNetNuke. UI. Containers. Container "%>
<% @ Register TagPrefix = "dnn" TagName = "ACTIONS" Src = "~ /Admin/Containers/SolPartActions. ascx "%>
<% @ Register TagPrefix = "dnn" TagName = "ICON" Src = "~ /Admin/Containers/Icon. ascx "%>
<% @ Register TagPrefix = "dnn" TagName = "TITLE" Src = "~ /Admin/Containers/Title. ascx "%>
<% @ Register TagPrefix = "dnn" TagName = "VISIBILITY" Src = "~ /Admin/Containers/Visibility. ascx "%>
...
<TD valign = "middle" nowrap> <dnn: ACTIONS runat = "server" id = "dnnACTIONS"/> </TD>
<TD valign = "middle" nowrap> <dnn: ICON runat = "server" id = "dnnICON"/> </TD>
<TD valign = "middle" width = "100%" nowrap>
<Dnn: TITLE runat = "server" id = "dnnTITLE"/>
</TD>
...
From the ascx file, we can see that dnnTitle is also a Control. How can I change the name?
View Source File ~ /Admin/Containers/Title. ascx
The Title contains a DNNLabelEdit:
<% @ Control Language = "vb" AutoEventWireup = "false" Inherits = "DotNetNuke. UI. Containers. Title" CodeFile = "Title. ascx. vb" %>
<% @ Register TagPrefix = "dnn" Namespace = "DotNetNuke. UI. WebControls" Assembly = "DotNetNuke. WebControls" %>
<Dnn: DNNLabelEdit id = "lblTitle" runat = "server" cssclass = "Head" enableviewstate = "False" MouseOverCssClass = "LabelEditOverClass"
LabelEditCssClass = "LabelEditTextClass" EditEnabled = "True"> </dnn: DNNLabelEdit>
DNNLabelEdit inherits from the Label.
More precise code modification should be:
Control title = (Control) this. ContainerControl. FindControl ("dnnTITLE ");
If (title! = Null)
{
Label lbTitle = title. FindControl ("lblTitle") as Label;
If (lbTitle! = Null)
{
LbTitle. Text = objTYDMItem. Title;
}
}
4. Exceptions in the title
However, DNN also supports the syntax of [TITLE: 1]. When compiled from HTML to ascx, DNN changes the Object ID to "dnnTITLE1 ".
Control title = (Control) this. ContainerControl. FindControl ("dnnTITLE ");
Return null.
All our programs are forced to be rewritten
Foreach (Control ctl in this. ContainerControl. Controls)
{
If (ctl. ID = null)
Continue;
If (Regex. IsMatch (ctl. ID, "dnnTITLE "))
{
LbTitle = title. FindControl ("lblTitle") as Label;
Break;
}
}