Custom ASP.NET Control Analysis (2)

zhaozj2021-02-17  53

Custom ASP.NET Control Analysis (2)

The previous analysis of the basic syntax of custom controls. This time the control is written as an example.

In ASP.NET, when you want to confirm your confirmation of Button's Click event, but the Button button cannot meet this requirement. It is aimed at this request to write your own control.

============================================================================================================================================================================================================= ====================

Inheritance: System.Web.ui.WebControls.Button

Control function: pop-up confirmation message box

Control Properties: Message (information displayed in the Message box)

Control method: no need

Control event: no need

How to use: "OK" The Button_Click event of the execution button, "Cancel" does not perform any events.

Imports system.componentmodel

Imports System.Web.ui

Namespace WebControls

")> Public class confirmButton

'Inheriting button

Inherits System.Web.ui.WebControls.Button

'Provide unique namespace for any server control included

Implements inamingcontainer

DIM _MESSAGE AS STRING

'Define the Message properties.

Property [message] () AS STRING

Get

Return_Message

END GET

Set (byval value as string)

_Message = Value

End set

End Property

Public Sub New ()

_Message = ""

End Sub

'Override the output of the control

Protected Overrides Sub Render (Byval Output As System.Web.ui.htmlTextWriter)

'Add a client onclick event for the control.

If Me.Message.trim <> "" "" "", "JScript: if (! Confirm ('" & me.Message & ")) Return False;")

Me.attributes.add ("onfocus", "jscript: this.blur ();")

MyBase.Render (Output)

End Subend Class

End Namespace

At this point, the control is written, you see if it is very simple.

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

New Post(0)