c# - asp.net textbox lostfocus javascript调用,代码看起来不错但无法编译
问题描述
我不明白我的代码有什么问题。这是非常基本的,但仍然存在错误。
在标题标签中,我有以下脚本,您可以跳过对最后一个函数的注意,这是我回答这个问题所需要的:
<script type="text/javascript">
function allowOnlyNumber(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
return false;
return true;
}
function checkboxalert() {
var active = document.getElementById("chkActive").checked;
var inactive = document.getElementById("chkInactive").checked;
if ((!active) && (!inactive)) alert("Please ensure that either Active or Inactive is checked before limiting search, otherwise, Active records will be assumed...")
}
function lostfocusLowPrice() {
if (getElementById("txtFindHighPrice").value = "" && getElementById("txtFindLowPrice").Value != "") getElementById("txtFindLowPrice").Value = getElementById("txtFindLowPrice").Value;
}
</script>
在我的网页设计中,我有这个:
<asp:TextBox ID="txtFindLowPrice" OnTextChanged="lostfocusLowPrice()" onkeypress="return allowOnlyNumber(event)" runat="server" Height="22px" Width="63px"></asp:TextBox>
我得到一个编译错误:
说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。
编译器错误消息:CS1061:“webform1_aspx”不包含“lostfocusLowPrice”的定义,并且找不到接受“webform1_aspx”类型的第一个参数的扩展方法“lostfocusLowPrice”(您是否缺少 using 指令或程序集引用?)
拼写匹配。代码非常基础。无法想象它可能是什么。其他 javascript 函数工作正常。
有任何想法吗?
解决方案
OnTextChanged 事件是一个服务器端事件,所以这里它在 .cs 文件中搜索 lostfocusLowPrice 方法并抛出上述错误。了解有关 OnTextChanged 事件的更多信息。请参考以下链接。 https://meeraacademy.com/textbox-autopostback-and-textchanged-event-asp-net/
下面还有一个: ASP 文本框调用 javascript 函数
推荐阅读
- c++ - 这段代码有什么错误,在二维向量中如何添加额外的元素?
- python - 未检测到 CSS 文件
- python - 使用 kubernetes 在 python 上实现 try/except 使用 GKE 的 python 客户端
- amazon-web-services - AWS MWAA(托管 Apache 气流);以编程方式启用 DAG
- modx - 动态占位符
- java - 创建 geotools 对象时如何使用特定的 CRS?
- mongoose - Mongoose 嵌套别名
- c++ - 如果在线程中执行,简单的 Winsock 服务器将不起作用
- google-sheets - 在查询中使用日期值格式时如何按日期排序?谷歌表格
- python - 如何使用 discord.py 自动发送消息?