如何使用updatepanel局部刷新实现注册时对用户名的检测

本篇内容介绍了“如何使用updatepanel局部刷新实现注册时对用户名的检测”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

通过将控件放入到updatepanel中,实现局部刷新。
前台代码:

复制代码 代码如下:


<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>     //必须有且写在updatepanel前面
<asp:updatepanel runat="server" id="updatepanel1">
<contenttemplate>
  <asp:textbox runat="server" id="txtname"></asp:textbox>
  <asp:button runat="server" id="btn" text="检测" onclick="btn_click"></asp:button>
  <asp:label runat="server" id="tip"></asp:label>
</contenttemplate>
</asp:updatepanel>

后台代码:

复制代码 代码如下:


protected void btn_Click(object sender, EventArgs e)
{
  if (this.txtname.Text == "user1")
  {
    this.tip.Text = "用户名已存在";
  }
  else
  {
    this.tip.Text = "用户名可用";
  }
}

“如何使用updatepanel局部刷新实现注册时对用户名的检测”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!