Не появляется сообщение клиента после нажатия на кнопку поиска - PullRequest
0 голосов
/ 09 октября 2018

Я работаю над alpha.dubaiexporters.com.Есть панель поиска, содержащая два ввода: Ключевое слово и Категории.Я хотел проверить часть ключевого слова.

Если пользователь ввел менее трех символов и нажал кнопку «Поиск», то должно появиться клиентское сообщение с надписью the entered input should be more than 3 characters.Я не получаю клиентское сообщение.

Ниже приведен мой код:

<input type="text" id="txtkeyword" name="s" runat="server" autocomplete="off">
<asp:Button ID="Search" class="dt-header-search-submit dt-button dt-button-danger" style="top:0px;width:226px;height:70px;" Text="Search" runat="server" onclick="doit" OnClientClick="return checkLength();" />

Ниже мой Javascript:

<script type="text/javascript">
        function checkLength() {
            var textbox = document.getElementById("txtkeyword");
            if (textbox.value.length < 3) {
                alert("The entered input should be 3 or more than 3 characters");
                return false;
            }
        }
    </script>

Код позади:

protected void doit(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(txtkeyword.Value))
        {
            try
            {

                String mainsearch1 = null;            
                mainsearch1 = txtkeyword.Value.Trim();
                if (mainsearch1.Length > 2)
                {
                    Response.Redirect("searchmain.aspx?mainsearch=" + mainsearch1 + "&querylevel=1");
                }


            }
            catch (Exception ex)
            {
            }
        }

        else if (!string.IsNullOrEmpty(txtserach.Value))
        {
            try
            {

                String cat = null;               
                cat = txtserach.Value.Trim();
                if (cat.Length > 2)
                {                 
                    Response.Redirect("searchcat1.aspx?cat=" + cat);
                }


            }
            catch (Exception ex)
            {
            }



        }


    }
}

Я не знаю, почему не вызывается функция javascript.

Ожидаемый вывод: я хочу получить это предупреждение, когда пользователь вводит менее трех букв в текстовом поле txtkeyword.

enter image description here

1 Ответ

0 голосов
/ 09 октября 2018

Работает нормально, попробуйте пожалуйста:)

function checkLength() {
debugger;
var textbox =$get("<%=txtkeyword.ClientID%>"); //document.getElementById("<%=txtkeyword.ClientID%>")
if (textbox.value.length < 3) {
alert("The entered input should be 3 or more than 3 characters");
return false;
}
}

Примечание: вы не можете получить доступ к элементу управления напрямую, когда runat = "server" есть

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...