ASP.NET 1.1中的用户控件公共共享变量不能按预期工作
时间:2020-03-06 14:52:28 来源:igfitidea点击:
假设我有一个包含一些用户控件的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中设置该值的子项。
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之外,还有谁有其他想法吗?
通过在用户控件中创建属性,现在可以正确传递值。
解决方案
就个人而言,这就是我要做的。
首先将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"