I have an aspx file like
<div style="<%= MyFunc() %>"><开发者_JAVA百科;/div>
but when I view it in the webpage, it gives the style string the literal as seen above, not the evaluated MyFunc. What could cause this?
EDIT:
it turns out, the tag had runat="server" on it... removing that fixed the issue. Why would that be?
It seems to work fine, are you defining a function like this?
public partial class _Default : System.Web.UI.Page
{
protected string MyFunc()
{
return "background-color:Red";
}
Use single quotes. ASP.NET outputs attribute values in double quotes literally. Single quotes will allow the script to be executed.
<div style='<%= MyFunc() %>'></div>
精彩评论