C# custom control to get internal text as string

Posted by Ed Woodcock on Stack Overflow See other posts from Stack Overflow or by Ed Woodcock
Published on 2010-05-20T08:59:09Z Indexed on 2010/05/20 9:50 UTC
Read the original article Hit count: 272

Filed under:
|
|

ok, I'm working on a custom control that can contain some javascript, and read this out of the page into a string field.

This is a workaround for dynamic javascript inside an updatepanel.

At the moment, I've got it working, but if I try to put a server tag inside the block:

<custom:control ID="Custom" runat="server">
    <%= ControlName.ClientID %>
</custom:control>

The compiler does not like it. I know these are generated at runtime, and so might not be compatible with what I'm doing, but does anyone have any idea how I can get that working?

EDIT

Error message is: Code blocks are not supported in this context

EDIT 2

The control:

[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;
        }
    }
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about custom-controls