tags:

views:

31

answers:

2

Hi guys,

I worked with: http://stackoverflow.com/questions/1648675/asp-net-ajax-check-for-registration-as-a-user

It has a few errors, I don't understand:

1) It worked only one time for one textbox. If the textbox is edited a second time, the breakpoint will not be hited. Why?

2) For my Email, I have a check, that there is no duplicate, when there is one, there should the set an error panel visible, but it don't show.

        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.";
        }
    }
A: 

After an update panel updates you must reinitialise the javascript on the html elements inside it.

So, to the end of your method you could add:

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);
}

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

Andrew Mcveigh
I have no onChange JavaScript?!
Kovu
Sorry, I didn't look at the link for long. Rippo uses the "ontextchanged" event... in which ASP writes the onchange stuff for you.
Andrew Mcveigh
If the updatemode is conditional, did you call up1.Update() ?
Andrew Mcveigh
+2  A: 

When the update mode is conditional

<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>

You need to call

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"
}

Sorry I'm a bit rusty, it's a while since I've used update panels.

Andrew Mcveigh
Perfect, thank you
Kovu