Automatically add MultipartForm-Data encoding type for HTMLINPUTFILE

zhaozj2021-02-17  45

Imports System.Web.ui

Imports system.componentmodel

Public Class UploadFile

Inherits System.Web.ui.WebControls.WebControl

'Set the encoding type used by the browser when sending the form of data to the server

The 'Multipart / Form-Data form data is encoded as a message, and the page on the page corresponds to a portion.

Protected Overridable Sub Ensureenctype ()

Dim Parent as system.web.ui.control = me.parent

While Not (PARENT IS NOTHING) Andalso Not (Parent.Gettype is gettype (system.web.ui.htmlcontrols.htmlform)) Andalso Not (Parent.GetType is gettype (system.web.ui.page))

Parent = parent.parent

End while

Dim myform as system.web.ui.htmlcontrols.htmlform = pent

IF not (parent is nothing) THEN

MyForm.Enctype = "Multipart / Form-Data"

END IF

End Sub

'Rewote the Tagkey property. Writing an HTML tagged as Input

Protected overloads overrides readonly property tagkey () as system.Web.ui.htmlTextwritertag

Get

Return HtmlTextWritertag.input

END GET

End Property

'Rewrive the onprender method in custom server control,

'When requesting custom controls from an ASP.NET page, the onprender method is called on the prerender phase of the page (when the server control will be present to the PAGE object included).

Protected Overloads Overrides Sub onprender (Byval E AS System.EventArgs)

Mybase.onprender (e)

If not (me.page is nothing) then 'If the page is actually available

ME.ensureEnctype ()

END IF

End Sub

Protected Overloads Overides Sub Render (Byval Writer As System.Web.ui.htmlTextwriter)

IF not (me.page is nothing "

Me.page.verifyrenderingInServerForm (me) 'confirms that the ASP.NET server control specified for the runtime is included in the HTMLFORM server control (

)

END IF

Mybase.addattributestorender (Writer)

Mybase.render (Writer)

End Sub

Protected Overloads Overides Sub AddattributeStorender (Byval Writer As System.Web.ui.htmlTextWriter)

Mybase.addattributestorender (Writer)

'Output HTML - File control

Writer.addattribute (HTMLTextWriterattribute.Type, "File") Writer.Addattribute (HtmlTextWriterattribute.Name, Me.Unique)

End Sub

END CLASS

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

New Post(0)