Extending Element in ScriptSharp, unable to call Element's methods

StackOverflow https://stackoverflow.com/questions/22882492

  •  28-06-2023
  •  | 
  •  

سؤال

I want to create custom control which will be able to reuse using Script#

 public class HallView : Element
 {
    public int HallId;

    public HallView(): base()
    {
       this.AddEventListener("click", Click, false);
    }

    private void Click(ElementEvent e)
    {
       Script.Alert("Click " + this.HallId);
    }
 }

then reuse HallView like

   HallView hall = new HallView();
   hall.ClassName = "hall clickableSection";
   container.AppendChild(hall);

The problem is I cannot call any Element's methods, even can compile and build Object does not have method addEventListener

or

Object does not have method appendChild

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

المحلول

The DOM doesn't support extending existing element types... so don't try it. Unspecified results.

You also can't new up DOM elements. You need to use document.createElement.

There are other ways to create the equivalent of custom controls - the most common of which is to create a jQuery plugin. There is a script# library project template for creating such plugins.

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