Persisting GridView Data Across PostBacks?

Apr 4, 2011

Alright, so here's my basic ASP.NET page setup: I've got a page with a GridView that has ContentTemplates in it. You can add a row and edit/remove rows at any time. There's a "New" button that creates a new row.

All of this data is bound to custom data objects. So if I have a GridView of "People" and each row has "FirstName", "LastName", and "Gender" (with TextBox and DropDown controls), I then have a "Person" object which has public properties for "FirstName", "LastName", etc. I have the binding set up correctly, and I can push data into the GridView from the object, and I persist the object with the Session variable. My page lifetime structure looks something like this:

Page_Load: Loads the List(Of Person) from Session()

Any events fire, and modify the List(Of Person).After any event, the List(Of Person) gets saved back into Session(), and is then DataBound to the GridView (and any subsequent fields are also DataBound, such as the DropDownList.

My question is: Whenever I fill in rows in the GridView, and then add a new row (there is no database saving going on whatsoever), my fields clear out and don't persist across PostBacks. So, how can I persist my custom data objects with databinding across postbacks?

View 2 Replies


Similar Messages:

Web Forms :: FileUploadControl: Persisting HTTPPostedFile Across Postbacks?

Jul 9, 2010

At present i am able to persist that using session InProc mode. except that i cant use either stateserver or sql server as the HTTPPostedFile is not serilizable. i can't use viewstate either for the same reason. Is there any work around to persist that httppostedfile across postbacks for session modes other than inProc or viewstate?

View 4 Replies

Persisting Checkbox State If Browser Back Is Clicked After Postbacks?

Feb 9, 2010

I've a checkbox with autopostback=true. If i check the checkbox the postback occurs and changes a label text. But if i click back in the browser the checkbox is not returning to its previous unchecked state. How can i bring back its state?

Can i write some JavaScript to persist the state of a control?

View 1 Replies

State Management :: Persisting DropDown List Attributes Across Page Postbacks?

Oct 12, 2010

how can DropDownList attributes be persisted accross page Postbacks?

Example:

DropdownList1.AutoPostBack = True
DropdownList1.items(0).Attributes.Add("Attribute1","somevalue")

On Postback the attribute is no longer available (ie. attributes.count=0).

I tried persisting using the code below, but was unsuccessful:

Before PostBack: ViewState.Add("DDL","DropdownList1")
On PostBack: DropdownList1 = ViewState("DDL")

This generated the error: DropDownlist is not marked as serializable.

I than tried:

Before PostBack: Session.Add("DDL","DropdownList1")
On PostBack: DropdownList1 = Session("DDL")

This did not err but attributes were still not available.

View 4 Replies

Forms Data Controls :: Persisting Color Of The Gridview Row On Click Of Hyperlink Column?

Mar 29, 2011

I have a requirement as mentioned below: 1. There is a gridview containing a linkbutton field (lnkgdvMerchant)in one of the column defination as menioned in the mark up below :Please note the bolded line of code for more details.

[Code]....

View 2 Replies

Forms Data Controls :: Code For Persisting Checked Rows In Gridview And Showing On Next Page During Paging?

Mar 2, 2011

I want to create a gridview with checkboxes. (only vb.net)

1) persist checkbox rows in paging in vb.net not c#

2) add the checked rows to datatable datasource and show on next page in paging

View 2 Replies

Forms Data Controls :: Retain Scroll Position Of Gridview During Postbacks In Firefox - Chrome

Feb 3, 2011

I have a gridview with scroll enabled. Means i have a gridview like this-

[Code]....

I want during postbacks scroll position of my gridview will not change. I have tried many articles on the web, but in some scrolling is retained only in IE, in some others scrolling position changes on clicking edit link of gridview. I want a good solution for IE, FF, Chrome

View 1 Replies

GridView Doesn't Remember State Between Postbacks?

May 13, 2010

I have a simple ASP page with databound grid (bound to an object source). The grid is within the page of a wizard and has a 'select' checkbox for each row.

In one stage of the wizard, I bind the GridView:

protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
// Bind and display matches
GridViewMatches.EnableViewState = true;
GridViewMatches.DataSource = getEmailRecipients();
GridViewMatches.DataBind();

And when the finish button is clicked, I iterate through the rows and check what's selected:

protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
// Set the selected values, depending on the checkboxes on the grid.
foreach (GridViewRow gr in GridViewMatches.Rows)
{
Int32 personID = Convert.ToInt32(gr.Cells[0].Text);
CheckBox selected = (CheckBox) gr.Cells[1].FindControl("CheckBoxSelectedToSend");

But at this stage GridViewMatches.Rows.Count = 0! I don't re-bind the grid, I shouldn't need to, right? I expect the view-state to maintain the state. (Also, if I do rebind the grid, my selection checkboxes will be cleared)

NB: This page also dynamically adds user controls in OnInit method. I have heard that it might mess with the view state, but as far as I can tell, I am doing it correctly and the viewstate for those added controls seems to work (values are persisted between postbacks)

UPDATE: Could this be to do with the fact I am setting the datasource programatically? I wondered if the asp engine was databinding the grid during the page lifecycle to a datasource that was not yet defined. (In a test page, the GridView is 'automatically' databound'. I don't want the grid to re-bound I just want the values from the viewstate from the previous post!

Also, I have this in the asp header: ViewStateEncryptionMode="Never" - this was to resolve an occasional 'Invalid Viewstate Validation MAC' message

For reference, my GridView is defined as follows:

[Code]....

View 3 Replies

C# - How To Avoid Persisting Data Through ViewState For A Child Control

Mar 3, 2010

I have a control (say, a DataGrid or a ComboBox) which is a child of a user control. I want to DataBind it on every request, rather than have it's state persist through ViewState. I need to leave EnableViewState=true however. This means, I think, that I need to call DataBind before TrackViewState() is called.

I read the fantastic blog post TRULY Understanding ViewState and it answers my question in 4. Initializing child controls programmatically. However, the article's solutions are less-than-ideal: create child controls dynamically (I'm not and can't -- too much existing code), use a 3rd party CodeExpressionBuilder (would much prefer this was in code-behind), and use OnPreInit (which "doesn't help you what-so-ever if you are developing a CONTROL").

View 1 Replies

Data Controls :: Persisting Data Using Spring Context C#

Dec 17, 2012

How To presist data using spring cotext in C# asp.net enviorn ment.

I have a class with username and user id properties.

at the time of loging i am creating class object and assinging values to properties.

Now i want to presist this object in Spring context. is it possible if Yes How?

View 1 Replies

Custom Server Controls :: Dynamic Nested Control Not Persisting Data?

Sep 21, 2010

how to make a control that can have controls nested inside it. I've made a jQuery tab browser class which uses a hidden field to remember which tab is selected and create the relevant client script to re-select it on postback...it works fine...

This is for web part development so all controls are created dynamically.

The problem is when I add a control to one of the tabs, the values set in that control disappear on postback..I understand there is a lot of information about user controls, viewstate and control state but nothing seems to give me access to those values...

I've boiled it right down to the basics and still can't get it to work unless the custom control has all its controls added in OnInit...which is bad news for me because I need to instantiate the browser, the use a 'AddTab' method to add tabs and controls to them, which occurs after the OnInit event and therefore I can't access the postback values!!

I get the feeling I'm missing something big here, I must be lol...here's is an example:

[Code]....

These controls have to be dynamically created, so I didn't see the need to make the ascx user controls..

View 4 Replies

Web Forms :: Saving Data For Postbacks?

Dec 31, 2010

I would like to save some data for use after a page postback. Here is an example of what I'd like to do:

Partial Class TestPage
Inherits System.Web.UI.Page
Private _CategoryID As String = ""
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
_CategoryID = "ABC"
Me.ViewState("CategoryID") = _CategoryID
Else
_CategoryID = CType(Me.ViewState("CategoryID"), String)
End If
End Sub
End Class

I've tried both session variables and view state. The page loads fine initially, but on postback I get the following error:

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

What am I doing wrong? How can I save this data for use after postback?

View 7 Replies

Web Forms :: Keeping Form Data Between Postbacks And Redirect?

Mar 28, 2011

I have a situation where I send data to different domain and return back to my domain. At this point I'm losing my form data. I know that we can use sessions, cookies or query strings. But i have large data in the form. So I can't use those. Can anyone best way to save form data between postbacks and redirect.

This is code which I'm using to redirect to different domain and come back to my domain:

[code]....

View 3 Replies

Forms Data Controls :: Maintaining Tab Position On Ajax Postbacks?

Jun 30, 2010

I have a grid and there are several dropdowns in a row of the grid.The dropdown selection change is driving other dropdowns in the row.

I put the dddls inside UpdatePanels still dropdowns are losing the tab position after a partial update. How is this generally done?

View 1 Replies

NHibernate Not Persisting Owned Objects?

Jul 30, 2010

I have just gotten a very odd error and I can't explain, or trace it out. My forum entity maintains a list of child forums. The list is internal, and exposed as an ienumerable, along with some methods like AddChild, FindChild and RemoveChild. Now to the code:

[Code]....

I have stepped through this several times, testing values along the way. It works perfectly, so I cannot explain the error. If a parent forum id is given, forumRepository.Update(parent) runs with no errors, it just doesn't actually save the new child to the db.

Incidentally... until I restart VS2010, the nhibernate session actually THINKS it HAS worked, and the new record shows on the page.

View 3 Replies

MVC :: Persisting Model State Across Requests?

Jan 3, 2011

I'm building a web application that has a particular model representing some events. Users need to be able to add N number of people to a given event. Choosing people is handled by a partial view.

I'm trying to build a menu that displays when users click "add a person" to the event. Because the event hasn't been filled out completely yet, there is nothing in the database to persist between requests.

I also have validation logic on the event page.

My proposed solution is to add the form to search or add for people on the event form itself and have a submit button that sends the values that have been added back to the server, where I can store them in ViewData or Session.

Unfortunately, doing this flags the validation.

My second solution is to load a partial view responsible for loading the UI to add/search for a person. I could add a little code on the method in the controller that returns a partial view storing the existing data in a session variable or viewdata. Trouble is, I have to submit the form to do it--again tripping the validation!!!

I'm wondering if perhaps I chose the wrong tool to do this...because in webforms, there would probably be a postback and you would just perform an operation on that postback. I'd like to avoid rewriting the application in webforms and am wondering if there are ways I'm overlooking in ASP.NET MVC.

View 2 Replies

C# - Persisting Dynamic Controls Over Postback?

Sep 30, 2010

I have a datagrid that loads on page_load.

In this instance I can't load the datagrid in page_init as the results of the datagrid are determined by a checkbox and the checkbox would always be set to true during page_init to the viewstate not being loaded.

I have an OnItemDataBound event on the datagrid that dynamically creates controls and later on I want to access the value of some of these controls (e.g. a text box)

Of course the problem is I can't access these controls values as they don't persist over a postback.

View 1 Replies

MVC :: Persisting The Country For The Logged On User?

Jun 22, 2010

I am new to ASP.NET MVC and I am using ASP.NET MVC 2. I am trying to implement the following feature and I need your expertise on this:

Authentication is Windows Authentication. Every user has at least one country associated to his/her account that he needs to manage.When a user navigates to the site we have to look up his/her associated country and persist it somehow (session?).With every call to the backend we need to pass the country as a filter. When a user has more than one country associated to his/her account, we need to display a dropdownlist on the site and the user should be able to change the "current" country at any time.
I have a couple of questions:

Where exactly in the lifecycle in the ASP.NET MVC framework should I retrieve the country or countries for the currently logged on user and where should this be persisted? In ASP.NET I would solve this by creating an intercepting filter using a HttpModule to set the Countries in the session state. What is a good way to implement this in ASP.NET MVC 2? (strongly typed session state wrapper?, magic strings?)Should I put a dropdownlist for the selection of the countries in my masterpage? How can I make sure that the current country remains selected in this dropdown?How can I make sure that with every call to the backend the country is passed, should I use an action filter?

View 4 Replies

Persisting Links On An Asp.net Page -a Job For Viewstate?

Dec 29, 2010

I've got a master page with a section for subnavigation links on it:

<div id="sub_nav" runat="server"></div>


I programatically populate this with Hyperlinks when my main asp:Menu data is bound depending on the address of the page I'm on.

This works fine and all my correct submenu stuff shows up on each page. The problem is that when one of these pages does a postback, I lose all the links that were in my sub_nav div.

Now, I could just populate the div with links every time regardless of whether the master page load is a postback or not, but I figured there is a better way of doing this. I was thinking enabling the viewstate on the div and links inside it might persist them through postbacks, but apparently that is not how viewstate works.

View 3 Replies

Persisting Datable On Post Backs

Mar 16, 2015

I am retrieving results from a SQL database based on a user file upload, and I am saving the returned results in a datatable. It can be up to 15,000 rows. I need to use this datatable in other requests in this same page - i.e. saving the data back to another table, exporting to a file....How can I store the datatable to access again? I read up on viewstate, session , and cache, but they all seem to have an affect on performance and memory.

View 7 Replies

Persisting Checkbox State While Paging In SPGridView?

Mar 23, 2011

Suppose I have created a spgridview with the following code.

[Code].....

To persist the checkbox states between pagebacks ,currently i am using session states.It has some draw backs.Now how can I persist the checked states,when the user manually checks all the checkboxes,how can i make a check on the header checkbox?

View 1 Replies

C# - Listbox Persisting Multiple Selected Items?

Jul 29, 2010

I am persisting the search selection criteria of a listbox onto another page which is called AreasLb. Multiple areas can be selected, I simply want to set the listbox items that the user selected as .Selected = true

I think the below code should work, but it doesn't, with no items in the Listbox being selected.

if (s == "Areas")
{
string[] area = nv[s].Substring(0, (nv[s].Length - 1)).Split(';');
int i = 0;
foreach (ListItem item in AreasLb.Items)
{
foreach (var s1 in area)
{
if (s1 == item.Value)
{
AreasLb.Items[i].Selected = true;
}
continue;
}
i = i + 1;
}
continue;
}

View 2 Replies

Javascript - Div's Class Not Persisting When 'back' Button Is Used?

Aug 18, 2010

I have an ASP.NET page that contains two div's. Both have search fields and a search button contained within each of them. When I first come to this page, Div A has the class 'SearchDiv' while Div B has 'SearchDivDisabled'. These classes change the appearance so the user knows which search type they currently have enabled.

When Div B is clicked, JavaScript changes it's class to 'SearchDiv', and changes Div A to 'SearchDivDisabled'. This all works like a charm. The problem I have is when a user changes to Div B, clicks Div B's search button (which obviously redirects to a results page), and then uses the browser's back button. When they return to the search page, Div A is enabled again, and Div B is Disabled, even though they last used Div B. In the search button event handler I set the class attribute of the Divs before I redirect, hoping this will update the page on the server so when the user returns, their last-enabled Div will still be enabled (regardless of which one was enabled when the page was first visited).I believe this involves the ViewState, but I'm unsure why the class attribute is not saved so when the user returns to the page it is restored.

Edit: Here is the button event handler code:

protected void RedirectToResults(int searchEnum, string resultPage)
{
ShowContainer(searchEnum);[code]....

RedirectToResults() is called from the actual button event handler with the enum representing the selected search panel and the results page url. SearchContainers is a dictionary mapping an integer to the search Div. The important code is the last line, where I'm updating the selected search container with the 'active' search class, rather than the disabled one (which I assign to the other div(s) )

Additional Update: I have been battling with this issue for the last couple days. I was sort of able to get the following code to work (in page_load):

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.0.
Response.AppendHeader("Expires", "0"); // Proxies.

But this really isn't a solution, as everything else that gets cached correctly is lost, which leaves me worse off than when I started. Everything else seems to persist fine, it is just the class of the div that is causing me struggles.

Edit: Just wanted to update this for anyone else that comes across this. While I believe there is a solution here with setting the cacheability of the page to force the browser to postback, I could not get it working 100% with all browsers (primarily Firefox was giving me fits, which is a documented bug). I do believe the cookie solution would work, but I felt that may be a bit more complex than necessary for just trying to store the state of a couple div's.

What I ended up doing was tying the div's class to the state of it's correlating radio button (there are radio buttons next to the div which allow the users a more visual way of enabling search panels). I noticed these radio buttons retained the correct checked value when the back button was used, so I could guarantee they would indicate the correct div to be enabled. So in JavaScript's onload I check which radio button is enabled, and then adjust the classes of the search div's accordingly. This is a pretty big hack, but has worked 100% across all browsers, and only took about 10 lines of JavaScript.

View 6 Replies

C# - Persisting Date Selections When Visible Month Changes?

Feb 21, 2011

Dim List As New List(Of DateTime)

Then in my button click event:

If InputBookinglength.SelectedValue.ToString = "2" Then
Dim paramstring As New StringBuilder
If Session("SelectedDates") IsNot Nothing Then
Dim newList As List(Of DateTime) = DirectCast(Session("SelectedDates"), List(Of DateTime))

[Code]....

This code works fine when selecting multiple days in one month. But when you switch to display a different month, the previous months selections are lost. how to persist the selections when the visible month changes.

View 1 Replies

JQuery :: Persisting CSS Change On Master Page?

Dec 23, 2010

Using ASP.Net 4.0, MVC 2, Visual Studio 2010.

I am building a chat control, which is a div with a background image, textarea, text box and some image. The CSS for this div on the Master Page is:

[Code]....

When a user navigates to the page where they can start a chat session by clicking on an icon, I use jQuery to change the CSS, like so:

[Code]....

The CSS for showing the chat is the same as the above CSS, only .chatWindowShow does not have the display:none property.

The problem is that once I navigate to another page, the div is hidden again, the CSS does not persist accross postbacks for some reason. What I want is that once the chat window is shown, no matter what other pages the users go to it will continue to show, until they click the close icon in the chat window.

So, how can I persist this CSS page accross all pages? I thought that removing the CSS class and adding the new one via jQuery actually modificate the inline HTML, but I guess not. Do I need to use some other jQuery to accomplish this?

Here is the HTML markup for my chat window:

[Code]....

And the jQuery which toggles the view when you click on the chatRight div:

[Code]....

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved