2009-11-03 105 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