如何在页面后面的代码中显示字符串

时间:2012-11-08 02:46:41

标签: asp.net variables user-interface code-behind

我正在尝试在我的aspx页面中显示我的代码中声明的公共字符串'TrialExtensionLengthDays':

<asp:Button ID="ExtendTrialButton" runat="server" Text="Extend Trial" CssClass="actionButton extendTrialButton"  title="Extend Trial by <%=TrialExtensionLengthDays%> days" OnClientClick="confirm('Extend the Customer Demo by <%=TrialExtensionLengthDays%> days?')"/>

以下是代码背后的相关部分:

Public Class EditTrialCustomer
    Inherits System.Web.UI.Page


    Public TrialExtensionLengthDays As String

Protected Sub Page_OnPreInit()
    TrialExtensionLengthDays = (System.Configuration.ConfigurationManager.AppSettings("TrialExtensionLengthDays"))
End Sub

为什么它不起作用?

2 个答案:

答案 0 :(得分:1)

尝试使用Tooltip属性而不是标题。

使用Page Load中的代码来设置此属性:

protected void Page_Load(object sender, EventArgs e)
    {
        ExtendTrialButton.ToolTip = "Extend Trial by " + TrialExtensionLengthDays + " days";
        ExtendTrialButton.OnClientClick = "confirm('Extend the Customer Demo by" + TrialExtensionLengthDays + " days?')";
    }

和你的asp页面只是:

<asp:Button CssClass="actionButton extendTrialButton" ID="ExtendTrialButton"  runat="server" Text="Extend Trial"  />

答案 1 :(得分:0)

尝试声明

  

TrialExtensionLengthDays StringBuilder而不是String