views:

64

answers:

1

Okay, here is my problem:

I have a form that requires to have two fieldsets that are almost identical but that collect different sets of data. These are contained in an UpdatePanel. The user enters the data in a form, and when they hit the "Add" button, this row is inserted into DataTable. The user should be able to enter as many rows as she wishes.

Since they are almost identical, I first got one working correctly, and then I used it as the base for the second one.

The problem is that now they the "Add" button is only triggered once. When I try to hit it again, nothing happens. No postback occurs.

I did some reasearch, and they advised to do register the buttons to the script manager http://stackoverflow.com/questions/786482/asp-net-button-click-event-not-firing

This didn't solve the problem.

Any ideas of what else I can try?

Edit 3: Solution: The problem was asp:RegularExpressionValidator with EnabledClientScript="true". It seems that the the control's javascript to validate collides and breaks the asp:Button's javascript when the control is rendered. If I disabled the ClientScript, then the buttons work.

The suggestion to look into the life cycle lead me to the right answer. The problem was that there wasn't any lifecycle happening on code behind. So after examining what the buttons renders into, it meant that it had to be a javascript related problem.

Edit 2: I disabled the asp:Validation controls and it is working. Any insights into this?

Edit 1:

Here is some code relevant to the issue

the button markup:

<td >
            <asp:Button ID="btnPrNew" Text="Add" OnClick="btnPrNew_Click" runat="server" />
</td>

And this is function than handled the onclick event

protected void btnPrNew_Click(object sender, EventArgs e)
{
    if (prQuantityValidator.IsValid && prPriceValidator.IsValid)
    {
        permanentRepairs = newItemizedDT();
        permanentRepairsTotal = populateDT(gvEstimatePermanentRepairs,    permanentRepairs) + addNewPrRow(); ;

        updateSubtotal(totalPermanentRepairs, permanentRepairsTotal);

        bindData(permanentRepairs, gvEstimatePermanentRepairs);
        clearPrForm();
    }
    else
    {
        erErrorMessage.Text = "Please enter only number amounts in Quantity and Unit Price field.";
    }
}
A: 

What's happening in your page lifecycle events (i.e. Page_Init, Page_Load, Page_PreRender)?

Are you handling stuff on every postback (are you checking Page.IsPostBack) which you should only handle on the first load of the page?

Robert W
Everything happens on Page_Load. I am not checking Page.IsPostBack.
Hugo Estrada
Thanks! Your question led me to search in the right place :)
Hugo Estrada