Kevin2205 Kevin2205 - 2 months ago 18
ASP.NET (C#) Question

Full String not displaying in title property when assigned from C# code ASP

I'm having a problem with trying to assign a string property of an object to the title property of a span in a aspx webform.

Basically, I have a string in the form of

"Hello this bright future!"

Assigned in the back end to a simple class as shown below:

public class DeviceDetails
{
public string Name { get; set; }
public string FailureDetails { get; set; }

public DeviceDetails(string name, string description)
{
Name = name;
FailureDetails = description;
}
}


The problem happens when I get to the front end and try to assign it. I get the first word in the FailureDetails and nothing else...

<span title=<%: deviceDetails.FailureDetails %>><%: deviceDetails.Name %></span>


Is there something I'm missing on the assignment?

Answer

You may need to add some quotes around the title like:

<span title='<%: deviceDetails.FailureDetails %>'><%: deviceDetails.Name %></span>

I have made here a JSFiddle where you can notice the differences between the two https://jsfiddle.net/5qb4LLv8/ . Without quotes it just displayes 'Hello'