asp.net - handle click event custom server control -


i have control imagebutton:

    ...      imagebutton btn;      public mycontrol()     {         btn = new imagebutton();           }      protected override void oninit(eventargs e)     {         base.oninit(e);         page.registerrequirespostback(this);     }      protected override void createchildcontrols()     {          btn.height = height;         btn.width = height;          btn.click += new system.web.ui.imageclickeventhandler(raiseleftclickevent);     }      private void raiseleftclickevent(object sender, imageclickeventargs e)     {         throw new notimplementedexception();     } 

when clicked button click event not fires.

i think must create click event in oninit scope..

protected override void oninit(eventargs e) {     base.oninit(e);     page.registerrequirespostback(this);     base.createchildcontrols();     btn.click += new system.web.ui.imageclickeventhandler(raiseleftclickevent); } 

update:

first, base class of control must webcontrol class.

and oninit scope define button's event:

protected override void oninit(eventargs e) {     base.oninit(e);     page.registerrequirescontrolstate(this);     controls.clear();      base.createchildcontrols();     btn.click += btnimagebutton_click;     controls.add(btn);  }   void btnimagebutton_click(object sender, eventargs e) {     //handle click event..  } 

hope helps..


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -