0

假设我有一个包含一些用户控件的 Web 表单。我的“主要”Web 表单的标题标签是在其中一个用户控件中生成的。将此数据传递给 Web 表单目前是这样完成的。

Public Sub SetPageValues(ByVal sTitle As String, ByVal sKeywords As String, ByVal sDesc As String)
    MySystem.Web.UI.Main.PageSettings(sKeywords, sDesc, sTitle)
End Sub

Main 是 Web 表单的名称。这是在 Main 中设置该值的 sub。

 Public Shared Sub PageSettings(ByVal strKeywords As String, ByVal strDesc As String, ByVal strTitle As String)
    Dim _lblTitle As System.Web.UI.webcontrols.Literal = lblTitle
    Dim _lblMetaDesc As System.Web.UI.webControls.Literal = lblMetaDesc
    Dim _lblMetaKeywords As System.Web.UI.WebControls.Literal = lblMetaKeywords
    Dim _lblMetatitle As System.Web.UI.WebControls.Literal = lblMetaTitle
    _lblTitle.Text = strTitle
    _lblMetaDesc.Text = "<meta name=""description"" content=""" + strDesc + """>"
    _lblMetaKeywords.Text = "<meta name=""keywords"" content=""" + strKeywords + """>"
    _lblMetatitle.Text = "<meta name=""title"" content=""" + strTitle + """>"
End Sub

在所有这些之后,我们正在运行池化内存并每 400 分钟回收一次,但是,页面标题会损坏并无法正确显示。除了迁移到新版本的 .net 之外,还有其他人有什么想法吗?

通过在用户控件中创建属性,现在可以正确传递值。

4

1 回答 1

1

就个人而言,这就是我会做的。首先 - 将 TITLE 更改为 HTML.GenericControl 在 ASPX 端,它看起来像这样:

<title runat="server" id="title" />

然后,我将 META 标签修改为 html 通用控件

<meta name="description" content="description" id="description" runat="server" />
<meta name="keywords" content="keys" id="keywords" runat="server" /> 

此时,您可以像这样修改值:

title.InnerText = "This Title"
keywords.Attributes("content") = "key,word"
description.Attributes("content") = "A demonstration of Setting title and meta tags" 
于 2008-09-29T14:08:42.693 回答