0

There are two Comboboxs, one button, and a GridView in a page.

When I click the button, the selected items of the Comboboxs should be inserted to the GridView and at the same time updated in database.

When I click the button it should not perform a postback. Users should be able to add lots ot records when hitting the submit button.

Servy
  • 202,030
  • 26
  • 332
  • 449
Stack User
  • 1,378
  • 5
  • 19
  • 40
  • 1
    You are going to have to use AJAX or some web service to save the value to the database. – Hogan Jul 26 '12 at 14:45
  • 1
    Use AJAX update panel : **http://msdn.microsoft.com/en-us/library/bb399001.aspx** – huMpty duMpty Jul 26 '12 at 14:45
  • 1
    You really should try to accept some answers. – phadaphunk Jul 26 '12 at 14:49
  • 1
    You won't be able to update the database without sending a request from back to the server (aka a postback). You can hide the fact that you are posting back from the user by using AJAX, but it's still happening. – Servy Jul 26 '12 at 14:49

1 Answers1

1

Here is what you need to do:

  1. Set a script function call in OnClientClick and return false from this method. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.onclientclick.aspx
  2. In this client method use JQuery AJAX to call a web method to update the db. http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
  3. Add a row to the table with jquery methods that manipulate DOM. Add table row in jQuery

Of course you can use an UpdatePanel but you have to insert the combo and the grid inside, so this is not going to save you server CPU and traffic.

Community
  • 1
  • 1
Amiram Korach
  • 13,056
  • 3
  • 28
  • 30