In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-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 solve the problem of registering Javascript in asp.net custom controls". In daily operation, I believe many people have doubts about how to solve the problem of registering Javascript in asp.net custom controls. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to solve the problem of registering Javascript in asp.net custom controls". Next, please follow the editor to study!
The copy code is as follows:
Protected override void OnPreRender (EventArgs e)
{
Base.OnPreRender (e)
RenderJS ()
}
Private void RenderJS ()
{
If (! Page.ClientScript.IsClientScriptBlockRegistered (SCRIPT_ID)) / / if you don't already have a registration statement, register
{
Page.ClientScript.RegisterClientScriptBlock (this.GetType (), SCRIPT_ID,SCRIPT_CONTENT)
}
}
Private const string SCRIPT_ID = "5B7A061B93D546A7A2601D56A8738DB9"; / / Custom identity Guid
Private const string SCRIPT_CONTENT = "\ nvar CB4949501DA_checkDouble = function (data) {\ nvar key = event.keyCode;\ nif ((key)
< 48 || key >57) & & key! = 46 & & key! = 45) {\ nreturn false;\ n}\ nelse {\ nif (key = = 46) {\ nif (data.indexOf (\ ".\")! =-1 | | data.length = = 0)\ nreturn false;\ n}\ nelse if (key = = 45) {\ nif (data.indexOf (\ "-\")! =-1 | | data.length! = 0) {\ nreturn false;\ n}\ nreturn true \ n}\ nvar CB4949501DA_checkInt = function (data) {\ nvar key = event.keyCode;\ n\ nif ((key)
< 48 || key >57) & & key! = 45) {\ nreturn false;\ n}\ nelse {\ nif (key = = 45) {\ nif (data.indexOf (\ "-\")! =-1 | | data.length! = 0) {\ nreturn false;\ n}\ n}\ nelse {\ nvar input = String.fromCharCode (key)\ nvar intData = parseInt (data + input);\ nif (intData > 2147483647 | | intData
< -2147483648) {\nreturn false;\n}\n}\nreturn true;\n}\nreturn true;\n}\nvar CB4949501DA_checkLong = function (data) {\nvar key = event.keyCode;\n\nif ((key < 48 || key >57) & & key! = 45) {\ nreturn false;\ n}\ nelse {\ nif (key = = 45) {\ nif (data.indexOf (\ "-\")! =-1 | | data.length! = 0) {\ nreturn false;\ n}\ n}\ nelse {\ nvar input = String.fromCharCode (key)\ nvar longstrData = data + input\ nif (longstrData.length > 19) {\ nreturn false;\ n}\ n}\ nreturn true;\ n}\ n\ n "
Then add the code to call the written javascript function:
The copy code is as follows:
Protected override void AddAttributesToRender (System.Web.UI.HtmlTextWriter writer)
{
Base.AddAttributesToRender (writer)
Writer.AddAttribute ("onkeypress", "return CB4949501DA_checkLong (this.value);");}
In addition, the reference file looks like this.
The copy code is as follows:
If (! Page.ClientScript.IsClientScriptIncludeRegistered ("reference js File 1") / / if it is not already referenced, then reference
{
Page.ClientScript.RegisterClientScriptInclude ("reference js File 1", "JS/MYJS.JS")
}
The view of the source code for the generated page is as follows:
The copy code is as follows:
Var CB4949501DA_checkDouble = function (data) {
Var key = event.keyCode
If ((key
< 48 || key >57) & & key! = 46 & & key! = 45) {
Return false
}
Else {
If (key = = 46) {
If (data.indexOf (".")! =-1 | | data.length = = 0)
Return false
}
Else if (key = = 45) {
If (data.indexOf ("-")! =-1 | | data.length! = 0) {
Return false
}
}
}
Return true
}
Var CB4949501DA_checkInt = function (data) {
Var key = event.keyCode
If ((key
< 48 || key >57) & & key! = 45) {
Return false
}
Else {
If (key = = 45) {
If (data.indexOf ("-")! =-1 | | data.length! = 0) {
Return false
}
}
Else {
Var input = String.fromCharCode (key)
Var intData = parseInt (data + input)
If (intData > 2147483647 | | intData
< -2147483648) { return false; } } return true; } return true; } var CB4949501DA_checkLong = function (data) { var key = event.keyCode; if ((key < 48 || key >57) & & key! = 45) {
Return false
}
Else {
If (key = = 45) {
If (data.indexOf ("-")! =-1 | | data.length! = 0) {
Return false
}
}
Else {
Var input = String.fromCharCode (key)
Var longstrData = data + input
If (longstrData.length > 19) {
Return false
}
}
}
Return true
}
At this point, the study on "how to solve the problem of registering Javascript in asp.net custom controls" 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.