The necessary condition to raise the custom control LoadPostData Method!

Source: Internet
Author: User
Control | Conditional custom control to raise the LoadPostData method, you need to include a control with an ID of This.uniqueid

You can add a hidden control to the group of controls!

Writer. Write ("<input type= ' hidden ' name= '" + Me. UniqueID + "' >")

Or simply a simpler approach, set the name attribute of the submit to me. UniqueID

Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
<defaultproperty ("Text"), ToolBoxData ("<{0}:login runat=server></{0}:login>") > Public Class Login
Inherits System.Web.UI.WebControls.WebControl
Implements IPostBackDataHandler
Public Event CheckError as EventHandler
Private _user as String
Private _pass as String


Public Function LoadPostData (ByVal postdatakey as String, ByVal postcollection as System.Collections.Specialized.NameValueCollection) as Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
_user = CType (postcollection (Me.uniqueid & ": User"), String)
_pass = CType (postcollection (Me.uniqueid & ":P ass"), String)
If _user <> _pass Then
Return True
Else
Return False
End If
End Function

Public Sub raisepostdatachangedevent () Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
Oncheckerror ()
End Sub

Public Sub Oncheckerror ()
RaiseEvent CheckError (Me, New System.EventArgs ())
End Sub


Protected Overrides Sub Render (ByVal writer as System.Web.UI.HtmlTextWriter)
Writer. RenderBeginTag (htmltextwritertag.table)
Writer. RenderBeginTag (htmltextwritertag.tr)
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.TD)
Writer. Write ("User name:")
Writer. RenderEndTag ()
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.TD)
Writer. AddAttribute (Htmltextwriterattribute.type, "TextBox")
Writer. AddAttribute (Htmltextwriterattribute.name, Me.uniqueid & ": User")
Writer. AddAttribute (Htmltextwriterattribute.maxlength, "30")
Writer. RenderBeginTag (Htmltextwritertag.input)
Writer. RenderEndTag ()
Writer. RenderEndTag ()
Writer. RenderEndTag ()


Writer. RenderBeginTag (htmltextwritertag.tr)
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.TD)
Writer. Write ("Password:")
Writer. RenderEndTag ()
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.TD)
Writer. AddAttribute (Htmltextwriterattribute.type, "Password")
Writer. AddAttribute (Htmltextwriterattribute.name, Me.uniqueid & ":P ass")
Writer. AddAttribute (Htmltextwriterattribute.maxlength, "30")
Writer. RenderBeginTag (Htmltextwritertag.input)
Writer. RenderEndTag ()
Writer. RenderEndTag ()
Writer. RenderEndTag ()



Writer. RenderBeginTag (htmltextwritertag.tr)
Writer. AddAttribute (Htmltextwriterattribute.cols, "2")
Writer. RenderBeginTag (HTMLTEXTWRITERTAG.TD)
Writer. AddAttribute (Htmltextwriterattribute.type, "Submit")
Writer. AddAttribute (Htmltextwriterattribute.name, Me.uniqueid)
Writer. AddAttribute (Htmltextwriterattribute.value, "submit")
Writer. RenderBeginTag (Htmltextwritertag.input)
Writer. RenderEndTag ()
Writer. RenderEndTag ()
Writer. RenderEndTag ()
Writer. RenderEndTag ()
End Sub
End Class





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.