In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "how to implement button control in asp.net before executing js and then background program". In daily operations, I believe that many people have doubts about how to implement button control in asp.net to execute js first and then execute background program. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful for you to answer the doubt of "how to implement button control in asp.net first execute js and then execute background program"! Next, please follow the editor to study!
In this paper, an example is given to describe the method of button control in asp.net to execute js first and then the background program. Share it with you for your reference. The specific analysis is as follows:
It seems not difficult to implement button control in .net after clicking js and then executing the daemon. Here let's take a look at an implementation method of button control in asp.net that executes js first and then executes the daemon. I hope it can help you.
With regard to button as a server control, I have always wanted to reduce its submission of data to the server. For those tests, it is better to implement them on the client side.
This requires javascript, but I find that javascript alone is not enough. The click event of the button server control is called "onClick", so javascript cannot use this event. Because of the same name. What I want to achieve is that when I click button, the client's javascript code is executed first, and then the background event is executed.
If you are using a html control, this problem does not exist. However, I just want to implement this function of the server control, and sometimes the server control is very easy to use.
First add a server control button to the aspx page
Add a client event to the server control button when the page is initialized. That is, add a line of code to the method Page_Load ():
The copy code is as follows:
If (! IsPostBack)
{
/ / add client events to button1
BtnSave.Attributes.Add ("OnClick", "return UserAddVerify ()")
}
UserAddVerify is a function implemented on the js side, which is mainly used to test the validity of the data.
The copy code is as follows:
Function UserAddVerify () {
Var userName = document.getElementById ("TxtUserName") .value
Var password = document.getElementById ("TxtUserPassword") .value
Var repassword = document.getElementById ("TxtUserPasswordConfirm") .value
Var identity = document.getElementById ("TxtUserIdentity") .value
Var mobile = document.getElementById ("TxtUserMobile") .value
Var realName = document.getElementById ("TxtUserRealName") .value
Var btnSave = document.getElementById ("btnSave")
Var identityReg = / (^\ d {15} $) | (^\ d {18} $) | (^\ d {17} (\ d | X | x) $) /
Var mobileReg = / 1 [3-8] +\ d {9} /
If (userName = = "" | | userName = = null) {
Alert ("user name cannot be empty")
Return false
}
Else if (password = = "" | | password = = null) {
Alert ("password cannot be empty")
Return false
}
Else if (repassword = = "" | | repassword = = null | | repassword! = password) {
Alert ("Sorry, the password is not the same two times")
Return false
}
Else if (identity = "" | | identity = = null | | identityReg.test (identity) = false) {
Alert ("Please enter a valid ID number")
Return false
}
Else if (mobile = = "" | | mobile = = null | | mobileReg.test (mobile) = = false) {
Alert ("Please enter a valid mobile phone number")
Return false
}
Else if (realName = = "" | | realName = = null) {
Alert ("name cannot be empty")
Return false
}
Return true
}
The return ture and false above are important, which determines whether to proceed, which should be to submit the data to the background to process the data. When true is returned, the button1_Click method (event) is executed in the background.
At this point, the study on "how to implement button control in asp.net first execute js and then execute background program" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.