Server side event fires ocassionally
<p>I have a drop down list of products, a grid view displaying ordered products and a button to add the selected product from the drop down list to the grid view.</p>

<p>When someone clicks the Add New Product button, my server side click handler only fires some times and doesn't fire other times. What could be the problem?</p>

<pre><code>    private void AddNewProductToGridView()
    {
        if (lstProducts.SelectedIndex &lt; 0) return;

        Response.Write("Selected Index: " + lstProducts.SelectedValue + 
            "&lt;br /&gt;Selected Text: " + lstProducts.SelectedItem.Text + 
            "&lt;br /&gt;Selected Value: " + lstProducts.SelectedValue);
    }

    protected void btnAddProduct_Click(object sender, EventArgs e)
    {
        AddNewProductToGridView();
    }
</code></pre>

<p><strong>Update</strong>
Ok, immediately after I posted the question, the button's server side click event started firing normally every time. :D</p>

<p>However, there is another problem. I also have a text box for quantity. I want that that button act as the default button of the page, i.e. when the user enters a quantity and presses the enter key, the same server side method <code>AddNewProductToGridView</code> must be called.</p>

<p>So, I set the <code>AutoPostBack</code> property of the textbox to <code>True</code> and added an event handler for the text changed event of the text box like so:</p>

<pre><code>    protected void txtQuantity_TextChanged(object sender, EventArgs e)
    {
        AddNewProductToGridView();
    }
</code></pre>

<p>About this I am positive that this event handler does not fire except for the first time I start the application.</p>

<p><strong>A later update</strong></p>

<p>I think I found the solution to my problem and learnt something new.</p>

<p>The Text_Changed event of the TextBox server side control, as the name suggests, does not fire if the Text property of the TextBox has not changed since the last post back. It is therefore unreliable as a means of triggering a postback.</p>
