Server Side Message Box in ASP.NET

xiaoxiao2021-03-06  115

IT's a Continuation of My Previous Article Server Side Message Box in ASP.NET.

When I start to upload my article, I am not able to upload it due to storage. That's why I intended to write it up like a continuation. Here I am providing Messagebox.vb, those who are not able to download a zip file, You May Use this. And build your own message box.

Imports system

Imports system.Web

Imports System.Web.ui

Imports System.Web.ui.WebControls

Imports System.Web.ui.htmlControls

Imports system.io

Imports system.drawing

Imports system.drawing.Image

Imports system.drawing.drawing2d

Public Class JS

Public Function JS ()

END FUNCTION

END CLASS

Public Class MessageBox

Inherits WebControl

Private strleft as string

Private stratop as string

Private INTBUTTON AS INTEGER

Private strmessage as string

Private strTITLE AS STRING

Private Strimage As String

Private strcss as string

Private strcsstitle as string

Private strcssmessage as string

Private strbuttonyes as string

Private strbuttonno as string

Private strbuttoncancel as string

Private strbuttonwidth as in

Private strmessageboxidyes as string

Private strmessageboxidno as string

Private strmessageboxidcancel as string

Private intMessageBoxwidth as in

Private IntMessageBoxheight as in

Private IntMessageBoxImageWidth as in

Private IntMessageBoxImageHeight AS Integer

Dim HomeDirectory As String

'Message Box Left Position

Public property messageBoxLeft () AS String

Get

Return strleft

END GET

Set (byval value as string)

Strleft = value

End set

End Property

'Message Box Top Position

Public property messageboxtop () AS String

Get

Return strtop

END GET

Set (byval value as string)

Strtop = Value

End set

End Property 'Number of Buttons You Want To Display In The Message Box

Public property messageboxButton () AS Integer

Get

Return IntButton

END GET

Set (ByVal Value As Integer)

INTBUTTON = Value

End set

End Property

'Customize Message You Want To Display In The Message Box

Public property messageboxMessage () AS STRING

Get

Return Strmessage

END GET

Set (byval value as string)

StrMessage = Value

End set

End Property

'Title you want to display in the message box

Public property messageboxTitle () AS STRING

Get

Return strTITEL

END GET

Set (byval value as string)

Strtitle = Value

End set

End Property

'Image you want to display in the message box (like information / warning)

Public Property MessageBoxImage () AS STRING

Get

Return Strimage

END GET

Set (byval value as string)

Strimage = Value

End set

End Property

'Message Box ID for Yes Button

Public property messageboxidyes () AS STRING

Get

Return StrMessageBoxIDyes

END GET

Set (byval value as string)

StrMessageBoxIDyes = Value

End set

End Property

'Message Box ID for no button

Public property messageboxidno () AS STRING

Get

Return StrMessageboxidno

END GET

Set (byval value as string)

StrMessageBoxidno = Value

End set

End Property

'Message Box ID for Cancel Button

Public property messageboxidcancel () AS STRING

Get

Return StrMessageBoxidcancel

END GET

Set (byval value as string)

StrMessageBox IDCancel = Value

End set

End Property

'Style you want to incorporate for message Box

Public property messageboxcss () AS STRING

Get

Return strcss

END GET

Set (byval value as string)

Strcss = value

End set

End Property

Public property messageboxcsstitle () AS STRINGET

Return strcsstitle

END GET

Set (byval value as string)

Strcsstitle = Value

End set

End Property

Public property messageboxcssmessage () AS STRING

Get

Return strcssmessage

END GET

Set (byval value as string)

StrcssMessage = Value

End set

End Property

'Message Box Text for Yes Button

Public property messageboxbuttonyestext () AS STRING

Get

Return strbuttonyes

END GET

Set (byval value as string)

strButtonyes = Value

End set

End Property

'Message Box Text for no button

Public property messageBoxButtonNotext () AS String

Get

Return StrButtonno

END GET

Set (byval value as string)

strButtonno = Value

End set

End Property

'Message Box Text for Cancel Button

Public property messageboxbuttoncanceltext () AS String

Get

Return strbuttoncancel

END GET

Set (byval value as string)

strButtonCancel = Value

End set

End Property

'Message Box Buttons Width

Public property messageBoxButtonWidth () AS Integer

Get

Return strbuttonwidth

END GET

Set (ByVal Value As Integer)

strButtonWidth = Value

End set

End Property

'Message Box Width

Public property messageBoxWidth () AS Integer

Get

Return IntMessageBoxwidth

END GET

Set (ByVal Value As Integer)

INTMESSAGEBOXWIDTH = VALUE

End set

End Property

'Message Box HEIGHT

Public property messageboxheight () AS integer

Get

Return IntMessageBoxheight

END GET

Set (ByVal Value As Integer)

INTMESSAGEBOXHEIGHT = VALUE

End set

End Property

'Message Box Image Width

Public Property MessageBoxImageWidth () AS INTEGER

Get

Return IntMessageBoxImageWidth

END GET

Set (ByVal Value As Integer)

INTMESSAGEBOXIMAGEWIDTH = VALUE

End setnd Property

'Message Box Image Heart

Public property messageBoxImageHeight () AS integer

Get

Return IntMessageBoxImageHeight

END GET

Set (ByVal Value As Integer)

IntMessageBoxImageHeight = Value

End set

End Property

Protected Friend Layer As HtmlGenericControl

Protected Friend ilayer as HTMLGenericControl

Protected Friend IMG as HTMLGenericControl

Protected Friend Div As HtmlGenericControl

Protected Friend Buttonok As Button

Protected Friend Buttonyes as button

Protected Friend Buttonno As Button

Protected Friend ButtonCancel As Button

Protected alertimage as system.web.ui.webcontrols.image

Public Sub New ()

MyBase.new ("DIV")

End Sub

Protected Overrides Sub Oninit (Byval E As Eventargs)

MyBase.oninit (e)

'Default Properties Settings for Message Box Control

If strleft is nothing then

Strleft = "250"

END IF

IF strop is nothing then

STRTOP = "250"

END IF

If strtitle is nothing then

Strtitle = "MessageBox"

END IF

IF INTBUTTON <0 THEN

INTBUTTON = 1

END IF

IF strmessageboxidyes is nothing then

StrMessageBoxidyes = "MessageBoxIDyes"

END IF

If strmessageboxidno is nothing then

StrMessageBoxidno = "MessageBoxidno"

END IF

IF strmessageboxidcancel is nothing then

StrMessageBoxIdcancel = "MessageBoxidcancel"

END IF

IF strcss is nothing then

Strcss = "" "

END IF

If strcssmessage is nothing then

StrcssMessage = "" "

END IF

IF strcsstitle is nothing then

Strcsstitle = "" "

END IF

IF strmessage is nothing then

StrMessage = "no message to display here."

END IF

IF INTBUTTON = 1 or intButton> 3 or intButton <1 THEN

If strbuttonyes is nothing trenstrButtonyes = "ok"

END IF

Elseif IntButton> 1 and Intbutton <4 THEN

If strbuttonyes is nothing then

StrButtonyes = "approve"

END IF

If strbuttonno is nothing then

strButtonno = "Cancel"

END IF

IF strbuttoncancel is nothing then

strButtonCancel = "ignore"

END IF

END IF

IF strbuttonwidth <5 THEN

StrButtonWidth = 70

END IF

IF IntMessageBoxWidth <10 THEN

IntMessageBoxWidth = 250

END IF

IF IntMessageBoxheight <1 THEN

INTMESSAGEBOXHEIGHT = 8

END IF

IF IntMessageBoxImageWidth <5 THEN

INTMESSAGEBOXIMAGEWIDTH = 36

END IF

IF IntMessageBoxImageHeight <5 THEN

INTMESSAGEBOXIMAGEHT = 36

END IF

If HomeDirectory Is Nothing Then

Homedirectory = me.page.Request.physicalApplicationPath

END IF

End Sub

Protected Overrides Sub CreateChildControls ()

'CREATING Message Box

DIM Myrow as tableerow

DIM Mycell As Tablecell

DIM MyTable as table = new table ()

MyTable.BorderWidth = new unit (0)

MyTable.cellspacing = 0

MyTable.Width = New Unit (intMessageBoxWidth)

MyTable.height = New Unit (intMessageBoxHeight)

Controls.add (MyTable)

Myrow = new tableerow ()

Myrow.BorderWidth = new unit (0)

MyTable.Rows.Add (MyRow)

mycell = new TableCell ()

DIM NewLabel As label = new label ()

NewLabel.Text = Strtertle

Newlabel.cssclass = strcsstitle

Mycell.controls.add (newLabel)

mycell.id = "Dragbar"

Mycell.columnspan = 5

Mycell.cssclass = strcsstitle

If strcsstitle = "" ""

Mycell.forecolor = system.drawing.color.white

Mycell.backcolor = system.drawing.color.darkBlue

Mycell.font.name = "verdana" mycell.font.bold = true

Mycell.font.size = new fontunit (8)

Mycell.Style.Add ("Cursor", "Hand")

END IF

MyRow.cells.Add (mycell)

Myrow = new tableerow ()

Myrow.BorderWidth = new unit (0)

MyTable.Rows.Add (MyRow)

mycell = new TableCell ()

Mycell.columnspan = 5

Mycell.cssclass = strcssmessage

If strcssmessage = "" "" "

Mycell.backcolor = system.drawing.color.lightgray

END IF

MyRow.cells.Add (mycell)

DIM MyRow1 as tableerow

DIM mycell1 as Tablecell

DIM myTable1 as table = new table ()

MyTable1.BorderWidth = new unit (0)

MyTable1.cellspacing = 0

Mycell.controls.add (myTable1)

Myrow1 = new tableerow ()

Myrow1.borderwidth = new unit (0)

MyTable1.Rows.Add (MyRow1)

mycell1 = new TableCell ()

Mycell1.cssclass = strcssmessage

mycell1.borderwidth = new unit (0)

mycell1.width = new unit (36)

Dim alertimage as system.Web.ui.WebControls.Image = new system.web.ui.webcontrols.image ()

AlertImage.height = new unit (intMessageBoxImageHeight)

AlertImage.width = New Unit (intMessageBoxImageWidth)

AlertImage.BorderWidth = new unit (0)

AlertImage.ImageURL = Strimage

mycell1.controls.add (alertimage)

MyRow1.cells.Add (mycell1)

mycell1 = new TableCell ()

Mycell1.cssclass = strcssmessage

mycell1.borderwidth = new unit (0)

Mycell1.cssclass = strcssmessage

If strcssmessage = "" "" "

Mycell1.horizontalalign = horizontalalign.center

mycell1.forecolor = system.drawing.color.black

mycell1.backcolor = system.drawing.color.lightgray

Mycell1.bordercolor = system.drawing.color.lightgray

Mycell1.font.name = "verdana"

Mycell1.bold.bold = trueMell1.font.size = new fontunit (8)

END IF

DIM NewLabel1 as label = new label ()

Newlabel1.text = StrMessage

Mycell1.controls.add (newLabel1)

MyRow1.cells.Add (mycell1)

Myrow = new tableerow ()

Myrow.BorderWidth = new unit (0)

MyTable.Rows.Add (MyRow)

IF INTBUTTON = 1 or intButton> 3 or intButton <1 THEN

mycell = new TableCell ()

Mycell.columnspan = 5

mycell.borderwidth = new unit (0)

Mycell.cssclass = strcssmessage

Mycell.horizontalalign = horizontalalign.center

If strcssmessage = "" "" "

mycell.forecolor = system.drawing.color.black

Mycell.backcolor = system.drawing.color.lightgray

mycell.font.name = "verdana"

mycell.font.bold = true

Mycell.font.size = new fontunit (8)

END IF

Buttonok = New Button ()

Buttonok.id = StrMessageBoxIDyes

Buttonok.text = strButtonyes

Buttonok.width = new unit (strbuttonwidth)

Buttonok.style.Add ("Cursor", "Hand")

Mycell.controls.add (Buttonok)

MyRow.cells.Add (mycell)

END IF

IF INTButton> 1 and Intbutton <4 THEN

mycell = new TableCell ()

Mycell.cssclass = strcssmessage

mycell.borderwidth = new unit (0)

Mycell.horizontalalign = horizontalalign.right

If strcssmessage = "" "" "

mycell.forecolor = system.drawing.color.black

Mycell.backcolor = system.drawing.color.lightgray

mycell.font.name = "verdana"

mycell.font.bold = true

Mycell.font.size = new fontunit (8)

END IF

Buttonyes = new button ()

Buttonyes.id = StrMessageBoxIDyes

Buttonyes.text = strbuttonyes

Buttonyes.width = new unit (strButtonWidth)

Buttonyes.Style.Add ("Cursor", "Hand") Mycell.Controls.Add (Buttonyes)

MyRow.cells.Add (mycell)

mycell = new TableCell ()

mycell.width = new unit (20)

mycell.borderwidth = new unit (0)

Mycell.cssclass = strcssmessage

If strcssmessage = "" "" "

Mycell.backcolor = system.drawing.color.lightgray

END IF

MyRow.cells.Add (mycell)

mycell = new TableCell ()

Mycell.cssclass = strcssmessage

mycell.borderwidth = new unit (0)

If strcssmessage = "" "" "

mycell.forecolor = system.drawing.color.black

Mycell.backcolor = system.drawing.color.lightgray

mycell.font.name = "verdana"

mycell.font.bold = true

Mycell.font.size = new fontunit (8)

END IF

IF INTBUTTON = 2 THEN

Mycell.horizontalalign = horizontalalign.left

Elseif INTButton = 3 THEN

Mycell.horizontalalign = horizontalalign.center

END IF

Buttonno = new button ()

Buttonno.id = StrMessageBoxidno

Buttonno.text = strButtonno

Buttonno.Width = New Unit (strButtonWidth)

Buttonno.attributes ("width") = strButtonWidth.toString ()

Buttonno.attributes ("Height") = strbuttonwidth.tostring ()

Buttonno.style.Add ("Cursor", "Hand")

Mycell.controls.add (Buttonno)

MyRow.cells.Add (mycell)

IF INTBUTTON = 3 THEN

mycell = new TableCell ()

mycell.width = new unit (10)

mycell.borderwidth = new unit (0)

Mycell.cssclass = strcssmessage

If strcssmessage = "" "" "

Mycell.backcolor = system.drawing.color.lightgray

END IF

MyRow.cells.Add (mycell)

mycell = new TableCell ()

Mycell.cssclass = strcssmessage

mycell.borderwidth = new unit (0)

Mycell.horizontalalign = horizontalalign.Leftif StrcssMessage = "" ""

mycell.forecolor = system.drawing.color.black

Mycell.backcolor = system.drawing.color.lightgray

mycell.font.name = "verdana"

mycell.font.bold = true

Mycell.font.size = new fontunit (8)

END IF

Buttoncancel = new button ()

Buttoncancel.id = StrMessageBoxIdcancel

Buttoncancel.text = strButtonCancel

Buttoncancel.width = New Unit (strButtonwidth)

Buttoncancel.Style.Add ("Cursor", "Hand")

Mycell.controls.add (Buttoncancel)

MyRow.cells.Add (mycell)

END IF

END IF

End Sub

Protected Overrides Sub AddattributeStorender (Byval Writer As HtmlTextWriter)

'Rendering Message Box Control to the Browser

Mybase.addattributestorender (Writer)

Writer.addattribute (HtmlTextWriterattribute.ID, "Showimage")

Writer.addattribute.style, "Z-Index: 9999; Left:" strLeft "PX; width:" strleft "px; position: absolute; top:" strogid: DXIMAGETRANSFORM.MICROSOFT.SHADOW (Color = 'DIMGRAY', DIRECTION = "135," Strength = "3;" ")

End Sub

END CLASS

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

New Post(0)