Click here to Skip to main content
15,920,664 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a grid, which contains a text box. By default, the grid contains 10 rows. When I click on add new row button on footer template , the entered previous details will be cleared off. Please give me the solution so that the previous details are not cleared on the button click.

What I have tried:

I have tried multiple update panel and AsyncPostBackTrigger
Posted
Updated 15-Jan-23 0:10am
v3
Comments
MadMyche 30-Jul-19 9:42am    
Show the actual code used for the grid and trigger... I forgot my tinfoil cap so I can't see where the error may be

Quote:
the grid contains 10 rows.
I am smelling that this code belongs to ASP.NET Web Forms, if so then you need to make sure that each time the page is sent to the server, you are storing the state of the controls and returning the state to the browser—which will be shown to the user after the page reload. Check out the following links to understand how this would work,

asp.net webforms and jquery: How to save/restore jquery state between postbacks? - Stack Overflow[^]
viewstate - How to store ASP.NET WebForms page state between requests - Stack Overflow[^]

One of the simple, clean and elegant ways to do that is using event.preventDefault(); that will prevent the form being submitted. But in this case, you need to upload the content yourself to the server using Ajax etc.
JavaScript
// This will work in ASP.NET Web Forms too, but would cause other issues
$("#btnId").click(function () {
   event.preventDefault();
});
Since your framework is ASP.NET Web Forms, you need to make sure that this JavaScript is called from the client side, like this,
C#
// return false; does the same thing, from 1000 ft above.
OnClientClick="uploadDataManually(); return false;" />
You can also use the control id that you set in ASP.NET Web Forms in the JavaScript code to control this behavior, that is up to you.
 
Share this answer
 
v2
UpdatePanel has nothing to do with maintaining the state and values of the WebForm Controls. You have to keep track of the state and store them somewhere in a storage medium (e.g Session, ViewState or Database) so can reference the values across postbacks. Check this article that I wrote many years ago: Dynamically Adding and Deleting Rows in GridView and Saving All Rows at Once[^]

If you want to avoid full page refresh, then don't use UpdatePanel control as it will only give more pain the butt. Instead, use AJAX with client-side grid (e.g jQuery grid, Webgrid, etc) and handle everything at the client (JavaScript code). One down-side though if you are going to client-side route is you will lose all the features that the server-side GridView has to offer since server controls are meant to be manipulated at the server.
 
Share this answer
 
use type button , the default is submit and it posts the form like this:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900