I have code in an Update Panel and even though on a button click i am inserting data into a db and simply calling Updatepanel.Update() the whole page is reloaded:
Gifts.ASPX
<table style='width:100%;'> <tr> <td> <asp:Label ID='Label2' runat='server' Text='Gift'></asp:Label> </td> <td> <asp:UpdatePanel ID='UpdatePanel3' runat='server' UpdateMode='Conditional'> <ContentTemplate> <asp:TextBox ID='txtNewGift' runat='server'></asp:TextBox> </ContentTemplate> </asp:UpdatePanel> </td> </tr> <tr>
Gifts.aspx.CS
protected void cmdAddGift_Click(object sender, EventArgs e) { OleDbConnection objConn = new OleDbConnection(DataSource); Random r = new Random(); int giftID = r.Next(1200, 14000); OleDbCommand objCommand = new OleDbCommand('Insert into Gifts (GiftID, Description) values (' + giftID + ','' + txtNewGift.Text + '')', objConn); ExecuteCommand(objCommand); PopulateGifts(objConn); txtNewGift.Text = ''; UpdatePanel3.Update(); }
Any ideas why this whole page would reload instead of just the textbox getting update?
Where is the button on Gifts.ASPX? If you put the button inside the UpdatePanel or use triggers you don’t need to call UpdatePanel3.Update(); from the code behind.