首页 > 解决方案 > 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 函数工作正常。

有任何想法吗?

标签: c#asp.nettextboxlost-focus

解决方案


OnTextChanged 事件是一个服务器端事件,所以这里它在 .cs 文件中搜索 lostfocusLowPrice 方法并抛出上述错误。了解有关 OnTextChanged 事件的更多信息。请参考以下链接。 https://meeraacademy.com/textbox-autopostback-and-textchanged-event-asp-net/

下面还有一个: ASP 文本框调用 javascript 函数


推荐阅读