Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add events to a Custom Web Control

2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report