2009-11-03 99 views
0

和我一起工作:ASP.Net: Ajax check for registration as a user?ASP.Net:阿贾克斯注册问题

它有一些错误,我不明白:

1)它的工作只是一个时间一个文本框。如果第二次编辑文本框,则不会激发断点。为什么?

2)对于我的电子邮件,我有一个检查,没有重复,当有一个,应该设置错误面板可见,但它不显示。

 protected void txtEMail_TextChanged(object sender, EventArgs e) 
    { 
     Business.UserHandling uh = new Business.UserHandling(); 
     if (uh.CheckIfEmailExists(txtEMail.Text)) 
     { 
      panelHelp.Visible = true; 
      lblHelp.Text = "EMail existriert schon."; 
     } 
    } 

回答

2

当更新模式是有条件的

<asp:scriptmanager runat="server" id="sm1" /> 
<asp:updatepanel runat="server" id="up1" updatemode="Conditional"> // here the updatemode is conditional ... 
<contenttemplate> 
    <asp:textbox runat="server" id="tbUsername" autopostback="true" ontextchanged="tbUsername_TextChanged" /> 
    <asp:customvalidator runat="server" text="Email already used" id="cusValEmail" /> 
    <asp:textbox runat="server" id="tbPassword" /> 
</contenttemplate> 
</asp:updatepanel> 

你需要调用

protected void txtEMail_TextChanged(object sender, EventArgs e) 
{ 
    Business.UserHandling uh = new Business.UserHandling(); 
    if (uh.CheckIfEmailExists(txtEMail.Text)) 
    { 
     panelHelp.Visible = true; 
     lblHelp.Text = "EMail existriert schon."; 
    } 
    up1.Update(); // call to update the update panel "up1" 
} 

对不起,我有点生疏,这是一段时间,因为我已经使用更新面板。

+0

完美,谢谢 – Kovu 2009-11-03 15:40:29

0

更新面板更新后,您必须重新初始化其中的html元素的JavaScript。

所以,你的方法结束时,你可以添加:

protected void txtEMail_TextChanged(object sender, EventArgs e) 
{ 
    Business.UserHandling uh = new Business.UserHandling(); 
    if (uh.CheckIfEmailExists(txtEMail.Text)) 
    { 
     panelHelp.Visible = true; 
     lblHelp.Text = "EMail existriert schon."; 
    } 
    // Re-init javascript 
    ScriptManager.RegisterStartupScript(Type, String, "add onchange js here", Boolean); 
} 

看到http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx

+0

我有没有onChange JavaScript? – Kovu 2009-11-03 12:54:52

+0

对不起,我没有长时间看链接。 Rippo使用“ontextchanged”事件...其中ASP为您写入onchangechanged事件。 – 2009-11-03 13:33:54

+1

如果updatemode是有条件的,你调用了up1.Update()吗? – 2009-11-03 13:44:12