C# - Save Data For UserControl To ViewState

Aug 5, 2010

At my user-control I populate listbox with collection and want save data in viewstatecontrolstate for further autopostback using.

protected void btFind_Click(object sender, EventArgs e)
{
var accounts = new AccountWrapper[2];
accounts[0] = new AccountWrapper { Id = 1, Name = "1" }; [code]...

ListBox is populated at button click. When I save accounts to ViewState listBox is empty, when not it displays collection good.

View 1 Replies


Similar Messages:

State Management :: UserControl Data In Viewstate And Retriving On Back Button?

Apr 16, 2010

I have a page with a few usercontrols. from a usercontrol I will redirect to a new page(response.redirect). Now On pressing the back button I want the data to persist for the usercontrols as well. I have tried it out by overriding DeterminePostBackMode, LoadPageStateFromPersistenceMedium, and SavePageStateToPersistenceMedium but all data except the ones within the usercontrol persist. i feel what i have tried is ok for the page data but for usercontrol data do i need to do something else.

P.S: I understand that i could be storing all user controls value in a session but I am looking for another way because its going to be a huge task taking each controls values in a session. I am not using any dynamically loaded user controls. May be if I know of a way of saving and restoring viewstate for user controls it would work but..

View 1 Replies

Does Gridview Save Data In Viewstate

Mar 31, 2011

i bind a DataTable to a gridview.i want to use the DataTable in some postback event, and ii want to use viewstate.
does gridview save data in viewstate? if no what is the best way to do this.

(full story :i have a custom gridview derived from standard asp.net gridview, and i put a button in header to export data to excel, i want to use data saved in viewstate to export to excel)

View 2 Replies

C# - Event To Save Data In ViewState Before Postback

Oct 14, 2010

I am looking for an event firing before a DropdownList auto-postback to save Listbox items (populated with JS) in the ViewState.I tried the OnSelectedIndexChanged event but it's fired too late.

View 5 Replies

Data Controls :: Save GridView Column Values To ViewState

Sep 20, 2015

ViewState["Index"] = reader[0].ToString();

Using sqlDataAdapter, I wanna save one column to view state like this.

View 1 Replies

C# - Repeater - Save Data In Viewstate With The Dropdownlist Selection Change Action?

Mar 21, 2011

I need some help in the technical approach with the following scenario:-

1) A dropdownlist with some options. It has a postback action on the selectedIndexChange server side event handler. For example, lets say it contains language options such as english, french etc.

2) Repeater with a label and the textbox control. For example label is Emp Name and textbox is containing the Emp Designation. We have to save emp designation in the various languages.

3) Every time i pick something from the dropdown, i have to flip the textbox control and fill the form. Now i want to save the given data of the texbox in the viewstate. So that every time, the user changes the dropdown selection, he can see the repeater data corresponding to the dropdown selection.

4) I guess some kind of relationship between the dropdown option and the repeater data is needed. But how can we make this thing work.

Now which is the best technique to save the data on the server side? I have to keep it in the viewstate.

View 1 Replies

Data Controls :: Save And Retrieve Data From ViewState

May 7, 2015

I have the following code:

protected void Page_Load(object sender, EventArgs e) {
if (!Page.IsPostBack) {
ViewState["NewRecord"] = "False";
}

[code]....

I have a button to Save data as well. In this Save routine, I simply look at the value of the ViewState to determine which button the user clicked, because that determines which code I should process. This used to work but is no longer working.

View 1 Replies

Forms Data Controls :: How To Save Viewstate Of Gridview After Cols / Rows Modified In PreRender

Oct 29, 2010

I have changed the look and feel of the grid by modifying the cols, rows in the gridview. I need to save this in the gridview viewsate, so that it load the modified look and feel next time it loads from the viewsate.

View 3 Replies

Can't Access Page Viewstate In Usercontrol?

Jun 11, 2010

I stored a object in viewstate on Page. Now when i access the same viewsate object on usercontrol,it shows as null. I even tried creating the same viewstate with same name in usercontrol and page.Both holds different value. I understand that viewstate is a protected property. How does this thing implement in above scenerio or is there any other reason for this behaviour.

Edit:

Usercontrol is there in the page markup. I am not loading it dynamically. I have a page EditFacilityworkType.aspx. On page I have a usercontrol FacilityWorkTypeDetails.aspx(FacilityWorkTypeDetails1). Inside this usercontrol i have a user control Workflow.aspx(Workflow1)

Page_Load() of Page I am retrieving workflowdetails on page_load() of page.

FacilityWorktype facilityWorkType = facilityDetails.GetFacilityWorktypeDetail(SessionHelper.FacilityWorkTypeID);
ViewState["WorkFlow"] = facilityWorkType.FacilityWorkTypeWorkFlow
Inside usercontrol FacilityWorkTypeDetails.aspx. I have a property
public FacilityWorktype FacilityWorkTypeDetails
{
get
{
#region Fill FacilityWorktype
return GetEntityFromControl();
#endregion
}
set
{
PopulateControls(value);
}
}

Now i set this property in page load of page

FacilityWorkTypeDetails1.FacilityWorkTypeDetails = facilityWorkType;
Inside Workflow.aspx, I have a property
/// <summary>
/// Property to fill entity object from controls on this page
/// </summary>
public WorkFlow WorkFlowDetails
{
get
{
return GetEntityFromControls();
}
set
{
BindTranscriptionMethodDDL(ddlTranscMethod);
PopulateControls(value);
}
}
Now PopulateControls() of FacilityWorkTypeDetails1, i am setting property of workflow1
private void PopulateControls(FacilityWorktype value)
{
Workflow1.WorkFlowDetails = value.FacilityWorkTypeWorkFlow;
}

Now when i am retrieving values from

private WorkFlow GetEntityFromControls()
{
WorkFlow workFlow = (ViewState["WorkFlow"] as WorkFlow) ?? new WorkFlow();
//workFlow is null
}

So now inside this function workFlow is null. I want to ask,why is it null when i have set viewstate in page.

View 4 Replies

Usercontrol Caching Viewstate Across Users?

May 25, 2010

I have a usercontrol with asp:textbox controls on it that also performs postbacks. If two users, who are both identified by a different session variable, postback the page within the same second, one user will see the other user's viewstate values in the text boxes. I have validated that this happens by setting a textbox, a session variable, and a cookie to the same value (the same value that identifies the user) and writing to the log when all three don't match. The text box's value is the one that is logged as the other user's value.ASP.net 3.5, IIS 6

View 2 Replies

Dataset Manually Put Into The Viewstate Of A Web UserControl Not Kept After Postback

Feb 2, 2010

I've created a Web User Control that is placed on the page at design time. It's purpose is to pop up with a grid of items the user is to choose from. So I've got a gridview on it. And this code in the usercontrol:

Public Property DataTable() As Data.DataTable
Get
If Not IsNothing(ViewState("_SelectGridDataTable")) Then
Return ViewState("_SelectGridDataTable")
Else
Return Nothing
End If
End Get
Set(ByVal value As Data.DataTable)
ViewState("_SelectGridDataTable") = value
End Set
End Property

So when the user clicks on a button on the page, I put this in the code on the page:

SelectGrid2.DataTable = GetContacts().Tables(0)
SelectGrid2.Show()

And this works fine. The grid pops up (using jQuery) and the grid is shown. The problem is, that when the user clicks the "OK" button on the UserControl, the ViewState("_SelectGridDataTable") is always nothing. And I don't get it, since it's in the viewstate.. ?!? So does viewstate here not REALLY mean viewstate?

View 1 Replies

UserControl, ViewState And Loosing Property Values?

Mar 29, 2011

this is about ASP.NET, ViewState, UserControls and loosing the values of my properties. It is an classic question by know, I know, and even though I have searched here and on Google for a resolution to this problem, I havent succeeded. On the contrary, the more I test different things, the less I understand it seems.

On top of this I am using ext.net and their so called DirectMethod's but I dont think that has much to do with this problem. There are numerous questions I have and I hope that this text will be fairly readable and understandable =)

The UserControl

I have a UserControl, Customers.ascx, that contains some Properties. The "most" important is *_CustomerId*. The _CustomerId is set in code-behind, in ext.net's "DirectMethod" like this (code below from the Page Customers.aspx):

[code]....

View 1 Replies

Property From A Custom UserControl That Is Saved In Viewstate Loses Its Value?

Jul 28, 2010

I have a custom control in an aspx page that has a property named Size

public int Size
{
get { return Convert.ToInt32(ViewState["CreativeSize"]); }
set { ViewState["CreativeSize"] = value; }
}

This property is set in the aspx page to a value lets say 500 during a postback called by a Button control that is in the page (not in the custom control).

I also have a button inside the custom control that raises a postback like this

protected void btnUpload_Click(object sender, EventArgs e)
{
if (fuBannerfile.HasFile)
if (fuBannerfile.FileContent.Length / 1024 > this.Size)
;//code here not important
}

When this event is called the "this.Size" property is 0. I also noticed during debugging that during Page_Load of the page, if i access the property like this:

int size = customControlId.Size;

the property is set to 500. But after that when the debugger reaches the event inside the control the property is 0.

View 1 Replies

Save Array In Viewstate?

Apr 28, 2010

I have Dim a(15) as integer i wont to save this array in Viewstate .

View 2 Replies

To Save A Variable In Viewstate?

Jun 9, 2010

I have searched the web for the answer and saw that mostly variables are saved in viewstate on page.prerender event. Then the value of the variable is set back in page load event.However, when I save a variable in viewstate on prerender or load events, how can viewstate store the value of the variable after it is changed dynamically on codebehind?

Let's say, after page is loaded, user clicked a button which changes the value of the variable in its onClick event. Then the postback event raised since the button was clicked. According to me, the new value should have been lost and cannot be saved in the viewstate if the variable is saved in the viewstate only in prerender event. Because on postback the prerender event wont fire and the value cannot be saved.

Shouldn't I save the variable in the viewstate just before the postback event rises?? If so, how can viewstate store the new value of the variable if the viewstate is saved in prerender event?

View 3 Replies

ViewState Used To Save A Value In Browser?

Mar 8, 2011

I set ASP.Net ViewState to off for a text box control, but the value for the name of the user is still there. Why is this so?

View 3 Replies

State Management :: Save An ImageButton To The Viewstate?

Sep 8, 2010

I have created a custom control that extends the class ImageButton, the thing is that I now also want to save this control to a viewstate.

View 4 Replies

State Management :: How To Save Int Array In Viewstate

Oct 25, 2010

how save int array in viewstate?

View 4 Replies

How To Save Value Across Postbacks For A Composite Control Without Using Viewstate

Oct 29, 2010

I have a composite control that has a couple of private fields that reference values in the cache and these private fields are called during the constructor method. Since a string key is used to identify the value in the cache, I must have a way of storing that string key in such a way that it is available at the time the control is instantiated, and I have to be able to reference it on postbacks without it changing.

In addition, this key is generated the first time the control is loaded, but it should not be changed again after that first time.

How can I accomplish this?

I have already tried saving it to viewstate, but that doesn't work because viewstate is not yet available at the time the control is instantiated.

I have tried using a private field and then checking against Page.IsPostback in the constructor and if it isn't postback, I assign a value to the private field, but on subsequent postbacks it looses it's value, and I can't reassign it in the Page.IsPostBack again because it is an autogenerated GUID.

View 3 Replies

State Management :: How To Save An Object Reference In A Viewstate

Nov 17, 2010

When I try to save an object reference in a view state it tries to save the object content using serialisation. to save the object reference only to apply to this object instance after postback?

View 5 Replies

State Management :: How To Save CheckBoxList Values Into The Viewstate

Dec 16, 2010

how to save the CheckBoxList values into the viewstate

for e.g.i've a CheckBoxList with 4 ListItems,

if I check 1 & 3 items, then I close the page

if I re-open the page, items 1 & 3 must be checked.

View 5 Replies

Web Forms :: Save The User Name And Password In Viewstate Or Session?

Feb 5, 2010

I am designing a site with that requires users to login in to access info. How do I save the user name and password in viewstate or session. so I can use it in other pages later.

View 2 Replies

AJAX :: Unable To Save FileName Of Upload File In ViewState Object

Jan 18, 2013

How to know the FileName AjaxFileUpload in the event Click of a Button without going through earnest for this is what I found that is to say that the FileName is only in the event Designed AjaxFileUpload1_UploadComplete.

protected void InsertButton_Click(object sender, EventArgs e) {
lblMSG.Text = ViewState["filename"].ToString();
}
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) {
ViewState["filename"] = e.FileName;
}
protected void AjaxFileUpload1_UploadComplete (object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) {
string filePath = "~ / upload /" + e.FileName;
AjaxFileUpload1.SaveAs (filePath);
}

View 1 Replies

State Management :: Save The Viewstate At The Server Side Instead Of __VIEWSTATE Hidden Field?

Feb 10, 2011

i am facing the following problem while saving the viewstate on the server side using the savepagestatetopersistencemedium, but this is not working for the pages which contains update panel.

View 2 Replies

Forms Data Controls :: UserControl Within Gridview Loses Properties When Usercontrol Events Are Trigered

Jul 17, 2010

This is page load

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ [code]...

But in my ascx.cs when IButton1_Click is trigered My name is null

private string _sname;
protected void Page_Load(object sender, EventArgs e)
{ [code]...

View 2 Replies







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