Get the App
SLTechnology News&Howtos  ›  Development  › 

How to add events to a Custom Web Control

Shulou Source: shulou.com Published: 2022-06-03 06:34:15 10月01日 Update

This article mainly shows you "how to add events to custom Web controls", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to add events to custom Web controls" this article.

-myRegister1.ascx foreground code-

The code is as follows:

Function Register () {

If ($('# myRegister1_txtUserName'). Val () = =') {

$('# spanUserName') .text ('Please enter a user name')

Return false

}

If ($('# myRegister1_txtPwd'). Val () = =') {

$('# spanPwd') .text ('Please enter your password')

Return false

}

If ($('# myRegister1_txtPwd1'). Val () = =') {

$('# spanPwd1') .text ('Please enter your password')

Return false

}

If ($('# myRegister1_txtPwd1') .val ()! = $('# myRegister1_txtPwd') .val ()) {

$('# spanPwd1') .text ('two passwords should be the same')

Return false

}

If ($('# myRegister1_txtEmail'). Val () = =') {

$('# spanEmail') .text ('Please enter mailbox')

Return false

}

Return true

}

User name:

Password:

Confirm password:

Mailbox:

-myRegister1.ascx background code-

The copy code is as follows:

Public partial class myRegister: System.Web.UI.UserControl

{

Public event MyRegeitserDelegate On_MyRegister

Protected void Page_Load (object sender, EventArgs e)

{

}

Protected void btnRegister_Click (object sender, EventArgs e)

{

If (On_MyRegister! = null)

{

MyRegister.userName=txtUserName.Text

MyRegister.pwd=txtPwd.Text

MyRegister.email = txtEmail.Text

On_MyRegister ()

If (MyRegister.isBool = = true)

{

Label1.Text = "registered successfully"

}

Else

{Label1.Text = "registration failed";}

}

}

}

Public class MyRegister

{

Public static string userName {set; get;}

Public static string pwd {set; get;}

Public static string email {set; get;}

Public static bool isBool {set; get;}

}

Public delegate void MyRegeitserDelegate ()

-WebForm event has no parameter .aspx foreground code-

The copy code is as follows:

-WebForm event has no parameter .aspx background code-

The copy code is as follows:

Public partial class WebForm event has no parameter: System.Web.UI.Page

{

Protected void Page_Load (object sender, EventArgs e)

{

This.myRegister1.On_MyRegister + = new MyRegeitserDelegate (myRegister1_On_MyRegister)

}

Void myRegister1_On_MyRegister ()

{

MyRegister.isBool = writer (MyRegister.userName, MyRegister.pwd, MyRegister.email)

}

Private bool writer (string userName, string pwd, string email)

{

Using (Stream stream = File.Open (@ "E:\ new.txt", FileMode.Append, FileAccess.Write))

{

Using (StreamWriter writer = new StreamWriter (stream))

{

Writer.WriteLine ("user name: {0}, password: {1}, mailbox: {2}", userName,pwd,email)

}

}

Return true

}

}

The above is all the content of the article "how to add events to Custom Web controls". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Code event password input control content user user name article mailbox foreground background learning help consistent successful easy to understand more organized knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Shulou Technology macOS Shulou Tech Info