2008-09-29 29 views
0

假設我有一個包含一些用戶控件的Web窗體。我的「主」網頁表單的標題標籤是在其中一個用戶控件中生成的。將這些數據傳遞給Web表單目前是這樣做的。用戶控制ASP.NET 1.1中的公共共享變量未按預期工作

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中設置該值的子集。

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之外,有沒有人有任何想法?

通過在用戶控件中創建屬性,現在可以正確傳遞值。

回答

1

個人而言,這是我會做的。 第一 - 在標題更改爲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"