【问题标题】:asp.net textbox lostfocus javascript call, code looks good but not compilingasp.net textbox lostfocus javascript调用,代码看起来不错但无法编译
【发布时间】:2019-06-13 00:59:40
【问题描述】:

我不明白我的代码有什么问题。 很基础,但还是有错误。

在标题标签中我有以下脚本,你可以跳过最后一个函数,这是我这个问题需要的:

    <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 函数工作正常。

有什么想法吗?

【问题讨论】:

  • Aamath 在下面有一个很好的答案,但是对于我想要做的事情有没有客户端解决方案?

标签: c# asp.net textbox lost-focus


【解决方案1】:

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

下面还有一个: ASP textbox calls javascript function

【讨论】:

  • 好答案。那么有没有客户端解决方案来做我想做的事情?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多