Amit Kumar

Amit Kumar

  • NA
  • 140
  • 40.9k

page is refreshed while i am using update panel

Aug 30 2013 12:34 AM

i am using update panel . a textbox is inside the update panel , still page is refreshed when text of textbox is chaned .

<form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <br />
        <table width="70%" cellpadding="5" cellspacing="10">
            <tr>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <td style="width: 70px;">
                            Name
                        </td>
                        <td>
                            <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" OnTextChanged="chkName"></asp:TextBox>
                        </td>
                        <td>
                            <div id="checkusername" runat="server" visible="false">
                                <asp:Image ID="imgstatus" runat="server" Width="17px" Height="17px" />
                                <asp:Label ID="lblStatus" runat="server"></asp:Label>
                            </div>
                        </td>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </tr>
            <tr>
                <td style="width: 70px;">
                    LastName
                </td>
                <td>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
                <td>
                </td>
            </tr>
           
        </table>
    </div>
    </form>

code behind is 

 protected void chkName(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(TextBox1.Text))
        {
            con = new SqlConnection(str);
            con.Open();
            cmd = new SqlCommand("select Name from info where Name=@1", con);
            cmd.Parameters.AddWithValue("@1", TextBox1.Text);
            SqlDataReader dbr = cmd.ExecuteReader();
            if (dbr.HasRows)
            {
                checkusername.Visible = true;
                imgstatus.ImageUrl = "del.gif";
                lblStatus.Text = "UserName Already Taken";
                System.Threading.Thread.Sleep(2000);
            }
            else
            {
                checkusername.Visible = true;
                imgstatus.ImageUrl = "available.gif";
                lblStatus.Text = "UserName Available";
                System.Threading.Thread.Sleep(2000);
            }
        }
        else
        {
            checkusername.Visible = false;
        }
    }



 


Answers (1)