如何在不刷新页面的情况下自动检查文本框中的现有数据。 [英] How to auto check existing data in textbox without refreshing the page.

查看:46
本文介绍了如何在不刷新页面的情况下自动检查文本框中的现有数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查文本框上的数据(UserID)而不刷新页面。实际上我想要当用户在文本框中写入任何UserID然后从db&结果在同一行而不刷新页面(即UserID可用或UserID不可用)。我正在使用ajax,但仍然页面令人耳目一新。查看我的代码:



Hi, I want to check data (UserID) on textbox without refreshing the page. Actually I want when user write any UserID in textbox then it check from the db & result on same line without refreshing the page (i.e. UserID available or UserID not available). I am using ajax for this but still page is refreshing. See my Code:

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:TextBox ID="UserID" runat="server" CssClass="w254" AutoPostBack="True" OnTextChanged="UserID_TextChanged"></asp:TextBox>
         <asp:Label ID="lbl_error" runat="server" Text="Label" Visible="False" Font-Size="Small"></asp:Label>
        <br />
        <br />
    </ContentTemplate>
</asp:UpdatePanel>
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox>



代码:


Code :

protected void UserID_TextChanged(object sender, EventArgs e)
   {
       lbl_error.Visible = true;
       int chk = 0;
       string chk_existing_email = "select userID from tbl_Registration where userID ='" + UserID.Text + "' ";
       chk = new CommonClass().Is_exist(chk_existing_email);
       if (chk == 1)
       {
           UserID.Focus();
           lbl_error.Text = "UserID is available!";
           lbl_error.ForeColor = System.Drawing.Color.Green;
       }
       else
       {
           UserID.Focus();
           lbl_error.Text = "UserID is not available!";
           lbl_error.ForeColor = System.Drawing.Color.Red;
       }
   }

推荐答案

这是因为你的文本框上有AutoPostback = True,所以它会回发。使用JavaScript事件,OnChange或Onblur并使用jquery的.ajax()方法。
It is because you have AutoPostback = True on your textbox, so it is going to postback. Use the JavaScript event, OnChange or Onblur and use jquery''s .ajax() method instead.


您可以使用Jquery来调用Web服务: -



You can use Jquery to call Web Service:-


#txtSearch)。selfocomplete({
source: function (request,response){
("#txtSearch" ).autocomplete({ source: function(request, response) {


这篇关于如何在不刷新页面的情况下自动检查文本框中的现有数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆