好的,我正在开发一个自定义控件,它可以包含一些JavaScript,并将其读取到一个字符串字段中。
这是解决更新面板内动态JavaScript的一种方法。
目前,我已经让它工作了,但如果我尝试在块内放置服务器标记:
<custom:control ID="Custom" runat="server">
<%= ControlName.ClientID %>
</custom:control>
编译器不喜欢这个。我知道这些是在运行时生成的,所以可能与我的操作不兼容,但有没有人知道我如何让它工作?
编辑
错误信息是:此上下文不支持代码块。
编辑2
控件:
[DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"), ControlValueProperty("Text"), DefaultProperty("Text"), ParseChildren(true, "Text"), AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class CustomControl : Control, ITextControl
{
[DefaultValue(""), Bindable(true), Localizable(true)]
public string Text
{
get
{
return (string)(ViewState["Text"] ?? string.Empty);
}
set
{
ViewState["Text"] = value;
}
}
}