Search code examples
asp.netvariablesuser-interfacecode-behind

How do I display string from code behind in page


I'm trying to display a public string 'TrialExtensionLengthDays' that's declared in my code behind, in my aspx page:

<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?')"/>

Here's the relevant part of the code behind:

Public Class EditTrialCustomer
    Inherits System.Web.UI.Page


    Public TrialExtensionLengthDays As String

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

Why's it not working?


Solution

  • Try using Tooltip property instead of title.

    Use code behind in Page Load to set this properties:

    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?')";
        }
    

    and your asp page just:

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