Web Forms error message: “This is not scriptlet. Will be output as plain text”

后端 未结 3 630
醉酒成梦
醉酒成梦 2020-12-09 08:38

In my ASP .NET Web Forms I have the following declarative code:

\' />         


        
3条回答
  •  北荒
    北荒 (楼主)
    2020-12-09 08:58

    You cannot use <%= ... %> to set properties of server-side controls. Inline expressions <% %> can only be used at aspx page or user control's top document level, but can not be embeded in server control's tag attribute (such as ..>).

    If your TextBox is inside a DataBound controls such as GridView, ListView .. you can use: <%# %> syntax. OR you can call explicitly DataBind() on the control from code-behind or inline server script.

    
    

    // code Behind file

    protected void Page_Load(object sender, EventArgs e)
    {     
            txtbox.DataBind();
    }
    

    ASP.NET includes few built-in expression builders that allows you to extract custom application settings and connection string information from the web.config file. Example:

    • Resources
    • ConnectionStrings
    • AppSettings

    So, if you want to retrieve an application setting named className from the portion of the web.config file, you can use the following expression:

     
    

    However, above snippet isn't a standard for reading classnames from Appsettings.

    You can build and use either your own Custom ExpressionBuilders or Use code behind as:

    txtbox.CssClass = TEXTBOX_CSS_CLASS;
    

    Check this link on building Custom Expression builders. Once you build your custom Expression you can display value like:

    
    

提交回复
热议问题