Custom control calls the function in the reference control page

zhaozj2021-02-17  48

Imports system.componentmodel

Imports System.Web.ui

Namespace WebControls

")> Public Class CustomToolbar

Inherits System.Web.ui.WebControls.WebControl

'Definition 3 button

Public withevents btnadd as system.web.ui.webControls.button

Public withevents btndelete as system.web.ui.webcontrols.button

Public WitHevents btnedit as system.Web.ui.WebControls.button

Private subsideton_ini (byref objbutton as button), byval text as string

Objbutton = new system.web.ui.webcontrols.button

Objbutton.text = text

Me.controls.add (objbutton)

End Sub

Public Sub New ()

Button_ini (btnadDNew, "new")

Button_ini (BTNDELETEDATA, "Delete")

End Sub

END CLASS

End Namespace

/

For the sake of concise, there is no incident, method, and attributes of the control. Compile it into a DLL

Call method:

Create a page Test.aspx to add the control into it. The control ID is CustomToolbar. Add: in the Page_init in Test.aspx.vb:

Public Class frMfabricItem

Inherits System.Web.ui.page

Protected dbacontrols as amms.dbacontrols

#Region "The code" of the web form designer "

'This call is required for the web form designer.

private subinitializecomponent ()

End Sub

Private sub page_init (byval sender as system.object, byval e as system.eventargs) Handles mybase.init

'Codegen: This method call is necessary for the web form designer

'Don't modify it using the code editor.

InitializeComponent ()

AddHandler CustomToolbar. Btnadd.click, addressof me.btnadd_click

AddHandler CustomToolbar. Btndelete.click, Addressof Me.Btndelete_Click

AddHandler CustomToolbar. BTNEDIT.Click, Addressof ME.BTNEDIT_CLICK

End Sub

#End region

Private Sub Page_Load (Byvale AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load

'Place the user code of the initialization page here

End Sub

'Define BTNADD_CLICK Procedures

Private sub btnadd_click (byval sender as system.object, byval e as system.eventargs)

...... ..

End Sub

'Define the BTNDelete_Click process

Private sub btndelete_click (Byval Sender As System.Object, ByVal E as System.EventArgs)

...... ..

End Sub

'Define btnadd _click process

Private sub btnedit_click (Byval Sender As System.Object, ByVal E as System.EventArgs)

...... ..

End Sub

END CLASS

/

The key is: AddHandler statement. There is also to be placed in the Page_init process.

Attachment:

AddHandler statement

See

REMOVEHANDLER statement | Handles | Event and Event Handle | AddHandler and RemoveHandler

Associate an event with an event handler.

AddHandler Event, Addressof EventHandler

Partial description

Event

The name of the event to be processed.

EventHandler

The name of the process of the event will be processed.

Note

The AddHandler and REMOVEHANDLER statements allow you to start and stop event processing at any time during program execution.

转载请注明原文地址:https://www.9cbs.com/read-30582.html

New Post(0)