Web窗体错误消息:"这不是scriptlet而。会为纯文本&QUOT输出; [英] Web Forms error message: "This is not scriptlet. Will be output as plain text"

查看:125
本文介绍了Web窗体错误消息:"这不是scriptlet而。会为纯文本&QUOT输出;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的ASP .NET Web窗体我有以下声明code:

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

<asp:TextBox runat="server" ID="txtbox" CssClass='<%=TEXTBOX_CSS_CLASS%>' />

恒TEXTBOX_CSS_CLASS是一个基类,页面的code-behind类继承自定义的:

The constant TEXTBOX_CSS_CLASS is defined in a base class that the page's code-behind class inherits from:

public class MyPageBase : Page
{
    protected internal const string TEXTBOX_CSS_CLASS = "myClass";
}

编辑 - 编译时间不过警告我说,这不是scriptlet而[原文]。将输出为纯文本。
言而有信,CSS类呈现为字面意思是&LT;%= TEXTBOX_CSS_CLASS%>

The edit-time compiler however warns me that "This is not scriptlet [sic]. Will output as plain text". True to its word, the css class is rendered as literally "<%=TEXTBOX_CSS_CLASS%>".

这是什么错误讯息,并有一种解决方法,所以我仍然可以使用一个不变的基类?

What does this error message mean and is there a workaround so I can still use a constant in a base class?

推荐答案

您不能使用&LT;%= ......%&GT; 来设置服务器端的性能控制。
内联前pressions &LT;%%GT; 只能在使用
ASPX页面或用户控件的顶级文档级,但不能中镶嵌
服务器控件的标记属性(如&LT; ASP:按钮...文本= LT;%%GT; ..&GT; )。

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 <asp:Button... Text =<% %> ..>).

如果您的文本框里面是一个数据绑定控件如GridView,ListView控件..你可以使用:&LT;%#%&GT; 语法。或者你可以显式调用的DataBind()从控制code-背后或内联服务器脚本。

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.

<asp:TextBox runat="server" ID="txtbox" class='<%# TEXTBOX_CSS_CLASS %>' />

// code Behind文件

// code Behind file

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

ASP.NET包括一些内置的前pression建设者,让您从的web.config 文件中提取自定义应用程序设置和连接字符串信息。例如:

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:


  • 资源

  • 的ConnectionStrings

  • 的AppSettings

所以,如果你想取得一个名为应用程序设置的className &LT;的appSettings&GT;的部分的web.config 文件,可以使用下面的前pression:

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

<asp:TextBox runat="server" Text="<%$ AppSettings:className %>" /> 

然而,上述片段是不是从阅读的appSettings类名的标准。

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

您可以创建并使用自己的自定义防爆pressionBuilders 或身后,用code:

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

txtbox.CssClass = TEXTBOX_CSS_CLASS;

检查此链接 在构建自定义前pression建设者。
一旦你建立你的自定义前pression可以显示像值:

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

<asp:TextBox Text="<%$ SetValue:SomeParamName %>"
    ID="setting" 
    runat="server" />

这篇关于Web窗体错误消息:&QUOT;这不是scriptlet而。会为纯文本&QUOT输出;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆