Search code examples
jqueryasp.nettelerik

unable to access asp button from front end after it is used at the back end


I have a form that is built from many divs, and it will show current form and hide others when I click on "Next" button - this is build using jQuery.

Now, I need to validate something at the back-end so that on autopostback, I will get an error message on a label.

This is the button:

<asp:Button runat="server" ID="btnNext" CssClass="btn btn-primary pull-right" Text="Next"  OnClientClick="return false;"/>

at back-end it is used like this:

If valid Then
            lblError.Text = String.Empty
            btnNext.Enabled = True
        Else
            lblError.Text = txtErr
            btnNext.Enabled = False
        End If

This is the jQuery script for the "Next" button:

btnNext.click(function (e) {
        if (divIndex < countDiv) {
            divIndex++;
            $(curDiv).show();
            $(curDiv).siblings().hide(); 
        }
        return false;
    });

The problem is, when I click "Next", nothing happen. If i remove the btnNext code from the back-end, the button works as it should.

Any thoughts?

ADDITIONAL INFO:

I am also using telerik for this project. To get the button changed (enable/disable) without loading the whole page, I'm using RadAjaxManager and btnNext is one of the updated control.

When I remove btnNext from the updated control, the form can work.


Solution

  • I actually manage to solve this. Here goes.

    Since I update the button using Telerik RadAjaxManager, I need to re-register the jQuery script to the button.

    https://docs.telerik.com/devtools/aspnet-ajax/controls/ajaxmanager/how-to/executing-custom-javascript-code-after-ajax-update

    So, I include the script right after btnNext is used at the back-code.

    If blnValid Then
         lblError.Text = String.Empty
         btnNext.Enabled = True
    Else
         lblError.Text = txtErr
         btnNext.Enabled = False
    End If
    
    ScriptManager.RegisterStartupScript(Page, GetType(Page), "Script", "initFormWizard();", True)