Javascript无法在asp.net用户控件中运行 [英] Javascript is not working in asp.net user control
本文介绍了Javascript无法在asp.net用户控件中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含许多javascript函数的用户控件。当我将这个添加到我的项目中时,一些功能正常工作但有些没有。
我使用下面的脚本来处理文本框的按键事件
I have a user control with many javascript functions. When I am adding this to my project ,some of the fuctions are working properly but some not.
I am using the below script for keypress event of a textbox
<script type="text/javascript">
var to; // variable to which we assign setTimeout function
var prm = Sys.WebForms.PageRequestManager.getInstance(); // Page Request Manager object
function onTxtKeyUp(e, buttonid) {
if (e.KeyCode != 9)
to = setTimeout(function () {
performSearch(buttonid);
}, 300)
}
function onTxtKeyDown() {
if (to) clearTimeout(to);
}
function performSearch(buttonid) {
if (prm.get_isInAsyncPostBack) {
prm.abortPostBack();
}
// $get("<%=lblStatus.ClientID %>").innerHTML = "Loading...";
__doPostBack(buttonid, "");
// __doPostBack("<%=btnSearch.UniqueID %>", "");
}
</script>
及其正常工作。下一个用于双击的是
and its working properly. the next I am using for a doubleclick is
<script type="text/javascript">
function clickButton(e, buttonid) {
debugger;
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt) {
bt.click();
}
}
</script>
且无效
and it is not working
推荐答案
get(<% = lblStatus.ClientID % > )。innerHTML =正在加载......;
__doPostBack(buttonid,);
// __doPostBack(<% = btnSearch.UniqueID %> , );
}
< / script >
get("<%=lblStatus.ClientID %>").innerHTML = "Loading..."; __doPostBack(buttonid, ""); // __doPostBack("<%=btnSearch.UniqueID %>", ""); } </script>
及其正常工作。下一个用于双击的是
and its working properly. the next I am using for a doubleclick is
<script type="text/javascript">
function clickButton(e, buttonid) {
debugger;
var evt = e ? e : window.event;
var bt = document.getElementById(buttonid);
if (bt) {
bt.click();
}
}
</script>
且无法使用
and it is not working
我可以看到你的用户控件有一个问题。
既然你没有外化你的用户控件的javascript,那么如果用户控件是在页面中多次使用,然后javascript代码将重复。
I can see one issue with your usercontrol.
Since you have not externalized your user control's javascript, so if the user control is used mutiple times in a page then the javascript code will get repeated.
这篇关于Javascript无法在asp.net用户控件中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文