开发者

ASP.NET Code won't evaluate in aspx file

开发者 https://www.devze.com 2023-03-18 08:01 出处:网络
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 evalu

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号