Store user input when updating repeater inside updatepanel - c#

I have a repeater inside UpdatePanel. Inside repeater item I have several text boxes. I also have "Add New" button to dynamically add new items to the repeater. The problem is that every time I press "Add New" all user input is erased. How do I update repeater with preserving user input?

Whenever a Postback occurs, Repeater control loses its state. You might want to perform following quick steps on a Postback.
Convert repeater data to some form of data array (DA) in code-behind.
Add empty element to DA.
Bind DA back to Repeater control.

Related

gridview in bootstrap modal popup issue

I used bootstrap modal popup and in that there is need to implement a gridview.
Using update panel,I added gridview and databinding is working properly.
In gridview row, there is a textbox where user can modify the existing values and update with a save button outside the gridview.
But when I fire the Save button command at server side, I am not getting the updated values instead I am getting old values by looping gridview rows controls.
How to get the updated values of from textbox in gridview inside bootstrap modal popup? I have used update panel also.
Please suggest.
In save button event, make sure that you are refreshing the gridview content adding databind() once you have saved the new values
YourGridView.DataSource = TheSource;
YourGridView.DataBind();
after hitting the update and fetching back the updated values you should register back the modal popup from c# at the end of the same event
ScriptManager.RegisterStartupScript(this,this.GetType(),"Pop", "openModal();", true);``
Customize the script according to your need

ASP.NET form with repeaters that dynamically generate input controls

I have a repeater control that pulls back some data from a database and creates a radiobuttonlist for values related to each row. I don't know how many rows will be coming back, so I don't know how many radiobuttonlists there will be. This repeater is inside of a form, and once I click "Submit" on the form I need to get the values from the radiobuttons generated by the repeater.
Any thoughts on how to do this?
There are a few options.
One is to use a nested Repeater to display the RadioButtons.
The other is to create the controls during the original repeaters. Repeater.ItemDataBound event.
In either case, you need to be very aware of the Page Lifecycle.
You'll want to avoid databinding in the Page_Load event, unless the databinding is being done with an if(!Page.IsPostback) block. If you fail to check for postback, you'll run into issues where the Page_Load calls a DataBind() call that then wipes the values of the repeater before any event handlers can use it.
Alternatively, you can do your binding in Page_Init, which occurs BEFORE the viewstate can be applied, so you won't lose your values.
You can also use USer Controls for the RadioButtons. There's a previous post that covers how to use nexsted user controls within a Repeater here.

Dynamics controls lost on postback

This old chestnut again.
My page is constructed as follows; I have a dropdownlist which is databound on first load. When the user selects a value from this, a postback is performed which then databinds a repeater control.
The ItemTemplate of this repeater control contains a placeholder control. In code behind in the ItemDataBound event of the repeater, I am adding two controls dynamically to this placeholder, a hiddenfield and a checkbox.
When the user clicks the save button, I then want to iterate over all those dynamically created hiddenfields and checkboxes and determine their values. However when the user clicks the save button, those controls no longer exist as shown in the page trace.
I know this is a lifecycle issue and the articles I've seen on this suggest using Init methods to dynamically create your controls but I can't because of the way my page works, e.g. the repeater control only appears and binds after a value is chosen from the dropdownlist.
What do I need to do to maintain the dynamic controls through the postback caused by clicking on the save button?
The problem is when you hit the save button probabily you dont re-bind the repeater and the controls you have added at run time withint the ItemDataBound event are not longer available(because they don't exist anymore)
Why don't you add those control at design time using the Eval function the set up the value of the hidden field?
You just don't create them dynamically just on the on selection change of the drop-down set visibility true or false for the repeater that will solve your problem.on post back you have to again create those control as they are Dynamically created.

Button in the Header Template of Repeater

I have an ASP.NET repeater which contains grid view and a panel which contains save button.
the repeater displays grid and save button for each employee..
if there are 5 employees then 5 grids and 5 save button will be displayed.
Now i want to move the save button to Header.. in that case i'll have only one save button for all the grids..
if any grid is modified and i click the Save button, how can we know which grid is edited.
pls help.
If the grids don't post back, i'm not sure it's possible to know which grid was edited. You could add an hidden field to the page (asp:HiddenField) and modify the value using javascript and then check the hidden value when the save button is pressed. Also, why do you have a save button? The gridview has full support for CRUD (Create/Read/Update/Delete) operations.
i think you can use "for each" to loop throw all items in the repeater
and you can check if there is any change in the item then save it if not then leave it and move to the next item.

Child GridView Hidden on Button Press, Needs to stay displayed

I have a child GridView which is displayed when a user selects a row in a the parent GridView. What the user can do is select items in the Gridview, which then go off to a results page. However, what I have is a button on the page which when clicked shows the user what they have selected. The problem is that when the button is pressed the child gridview is hidden, how do I (if it has been selected/displayed) keep it open/displayed?
Do I have to set up a variable which will hold whether the child gridview has been displayed, can I put it in the pages viewstate (I don't know anything about this as all this .net stuff is new to me)?
Thanks R.
Something quick you could try is to set
Visble=True
For your parent and child gridview in the button's handler
It's difficult to say without some sample code, but another possiblility is that when the button is clicked, the parent gridview is rebound to a data source (probably in the Page_Load event), but not the child gridview. Try rebinding the child gridview to its data source right after the parent gridview.
gvChildGrid.DataSource = {some data source};
gvChildGrid.DataBind();

Categories