سؤال

I could see any property defined in server control with intelsense on .aspx and assign value to it.But how can I work with my custom events - I can assign value to them only on .cs file.I mean I want work with them as with "OnInit" and others events.

    // server control
    static readonly object ourKey = new object();

    public event EventHandler MyEvent
    {
        add { Events.AddHandler(ourKey, value); }
        remove { Events.RemoveHandler(ourKey, value); }
    }

    // such I invokes event
    protected void OnMyEvent(EventArgs e)
    {
        EventHandler aH = Events[ourKey] as EventHandler;

        if (aH != null)
            aH(this, e);
    }

    // my aspx cant see [MyEvent]
     <hp:ServerControl1  MyEvent = "CustomEventHandler".../>

Should I define string properties and then using string methods name find and invoke it (if it possible)?

هل كانت مفيدة؟

المحلول

Check code for:

<hp:ServerControl1 OnMyEvent="...." />

Edited to show answer.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top