How To Use A Viewstate'd Object As A Datasource For Controls On User Control

Dec 29, 2010

I've got a listview on a control. Each row comprises a checkbox and another listview.

The outer listview is bound to a property on the control (via a method call, can't set a property as a SelectMethod on an ObjectDataSource it would appear) which is lazy loaded suchly:

[Code]....


The reason for the use of viewstate is this:

When an one of the checkboxes on one of the outer list view rows is checked or unchecked I want to modify the object that the ODS represents (for example I'll add a couple of Charge objects to the relevant Product object) and then rebind.

The problem I'm getting is that after every postback (specifically after checking or unchecking one of the rows' checkbox) my viewstate is empty. Thiss means that any changes I make to my viewstate'd object is lost.

Now, I've worked out (after much googling and reading, amongst many others, Scott Mitchel's excellent bit on ViewState) that during initial databinding IsTrackingViewState is set to false. That means, I think, that assigning the return from GetWebServiceProductLineChargeDetails() to the ViewState item in my Property Get during the initial databind won't work.

Mind you, even when the IsTrackingViewState is true and I call the Property Get, come the next postback, the viewstate is empty.

how I keep the object referenced by the ObjectDataSource in ViewState between postbacks and update it and get those changes to stay in ViewState?

View 1 Replies


Similar Messages:

Forms Data Controls :: Pass Parameter To Object Datasource In User Control?

Jun 30, 2010

I have a gridview inside a user control bind to an object datasource. Now I want to bind the object datasource with a parameter from parent page.

For this purpose I defined a public property in user control but how do I pass it with object datasource ?

I am calling from parent page like

myusercontrol.parameter=querystring["id"];

How to bind object datasource with my parameter ?

View 4 Replies

Forms Data Controls :: Using GridView With A User Control And Passing Object Into Control?

Jan 8, 2010

I would like to use the gridview paging feature and have built a gridview with a user control. The data source has lots of columns, so to make it easier I want to return a LIST<MyObject> and just pass <Myobject> into the user control rather than all the data elements. Not sure how I access the object of the data source to bind to the control. Assume it would be during ondatarowbound.

Also, my guess is there is a better way to do this than gridview. I'd take either solution that allows me to have easy paging and pass the complete object into the user control

View 7 Replies

Web Forms :: Assign User Control From Another User Control ? Giving Error Object Reference Is Not Set An Instance?

Feb 17, 2011

I am trying to assign user control from another user control ..first time its binding control successfully but when we refresh the data its giving error

saying "Object reference is not set an instance".

how to refresh data from another user control ...

My senerio below :

1 Aspx page

2. User control

calling usercontrol databinding method from aspx page but once it get refreshed ,not allowed to bind it again..

View 2 Replies

C# - Web User Control With Content Inside It / Object Reference Not Set To An Instance Of An Object

Aug 11, 2010

Usage :

[code]...

The problem is it gives me following error :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 21: {
Line 22: base.OnInit(e);
Line 23: _ContentTemplate.InstantiateIn(BodyControlSpace);
Line 24: }
Line 25:

View 3 Replies

DataSource Controls :: How To Pass An Object To The Selectmethod Of The Objectdatasource Control

Mar 31, 2011

how to pass an object to the selectmethod of the objectdatasource control?

View 2 Replies

C# - Viewstate Variable Lost On User Control Loaded Dynamically

Feb 12, 2010

I have a problem with ViewState. I have an aspx page that has a treeview on the left and an UpdatePanel with an ASP.NET Panel inside on the right. It is in that inner Panel where I load and unload dynamically user controls. I use that update panel to load dynamically controls.

I also made a custom control for my user controls because I need to pass some values from page. On that constructor I use ViewState to store these values.

The first time I load the user control I call its constructor with parameters. When I reload that user control on each postback I use its normal constructor.

My problem is I the values I've stored on ViewState has become null on successive postback.

Update:

This is a piece of my user control:

public class MyUserControl : System.Web.UI.UserControl
{
private int PKId
{
get { return ViewState["pkId"] as int; }
set { ViewState["pkId"] = value; }
}
public MyUserControl(int pkId)
{
this.PKId = pkId;
}
...
}

I'm following this article to load controls dynamically: http://msdn.microsoft.com/en-us/magazine/cc748662.aspx#id0070065.

Second Update:
I also set the same control ID when I load the user control at first time and on each reaload.

Maybe I can use another method to store these values like input hidden fields or Cache. I've choosen ViewState because I don't want to overload server with Session values for each user.

Third update:

I load the controls with this code:

System.Web.UI.UserControl baseControl = LoadControl(ucUrl) as System.Web.UI.UserControl;
if (baseControl != null)
{
baseControl.ID = "DestinationUserControl";
PanelDestination.Controls.Add(baseControl);
}

And reaload with this code:

DynamicControls.CreateDestination ud = this.LoadControl(TrackedUserControl) as DynamicControls.CreateDestination;
if (ud != null)
{
ud.ID = "DestinationUserControl";
PanelDestination.Controls.Add(ud);
}

View 4 Replies

State Management :: Viewstate Not Being Persisted Across Postbacks On Web User Control?

Mar 5, 2010

1) I found that my viewstate was not being persisted across postbacks for web user controls. I ensured that the Enable Viewstate property was set to true (of the page)

2) The Viewstate isnt being persisted on the 1st postback.

3) However, it is being persisted from the 2nd postback onwards.

I stepped through the code to ensure that the Viewstate had the 2 keys that I was adding on page load. However, on the 1st postback, the viewstate is empty. Everything is ok from the 2nd postback onwards.

[Code]....

View 3 Replies

Forms Data Controls :: Passing A Whole Object Through To The User Control Inside A Repeater?

Apr 16, 2010

I have a user control inside a repeater. I am binding a collection of objects to the repeater.

My user control has a public property to retrieve the object (setobject)

How do i pass each object through to the user control and not just the object property value? What is the syntax to do this?

[code]....

View 1 Replies

State Management :: Failed To Load Viewstate. The Control Tree Into Which Viewstate Is Being Loaded Must Match ?

Oct 9, 2010

Now here is the weird thing. First i am running it locally on the built in vs2008 web server.I load my control in fine, do a postback from a linkbutton, locally on my machine it all works fine, no issue.However when it goes onto my host, it falls over with the message:

Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.Now i also load controls dynamically and use postbacks and things in the admin area of the site...and that works fine, however my front end just keeps failing? See the code behing below:

[Code]....

View 1 Replies

DataSource Controls :: Simple Login Form - Object Reference Not Set To An Instance Of An Object?

Apr 20, 2010

im tryin to create a login form.

and am receiving the following error:

Object reference not set to an instance of an object

[Code]....

and heres my aspx page:

[Code]....

Stored procedure:

[Code]....

View 2 Replies

DataSource Controls :: Get Child Properties Using Parent Object Error / Cannot Access A Disposed Object

Feb 17, 2010

On DBML I have two entities as Parent, Child. I am trying to assign Child class properites in a Parent.

[code]....

I am getting the following Error:

Cannot access a disposed object.

Object name: 'DataContext accessed after Dispose.'.

View 2 Replies

DataSource Controls :: Getting Error - Object Reference Not Set To An Instance Of An Object?

Jul 27, 2010

[code]....

i'm having trouble because when it has no return value i get the error

Object reference not set to an instance of an object.

View 10 Replies

DataSource Controls :: Error - Object Reference Not Set To An Instance Of An Object

Jan 24, 2010

im using a sqldatasource and i want it to query a table chosen from a dropdownlist, so i wrote the following in the .cs file

[Code]....

im recieving this error msg: Object reference not set to an instance of an object (pointing to the line containing the select command)

i don't know what's the problem, i tired a hard-coded statement and it worked fine!

View 2 Replies

JQuery :: User Control Via Jquery And Control Events ViewState?

Jan 26, 2011

have a page that use JQuery to get markup of user control from a web services. it is successfully giving me what i want the markup etc.Jquery Code:

[Code]....

------------------

You can see that user control have a button that have a click event handler. i want this button to trigger on click. but when i click on this button i found server error "The state information is invalid for this page and might be corrupted."i can imagine what is going on viewstate is not valid for form for obivious reason......how can i fix this problem or update viewstate.

View 4 Replies

DataSource Controls :: Object Reference Not Set To An Instance Of An Object?

May 26, 2010

I am adding rows to table and setting value row/cell value, but for datetime field it is giving me error

Object reference not set to an instance of an object.

Initially I am adding a column to table as

table.Columns.Add("Upload Date",
typeof(DateTime));

Then I assigning value to row as

row["UploadDate"] = result["Execution Date"].ToString();

As I have I also null or empty value in the "Execution Date" field .

View 3 Replies

Server Controls In User Control Are Null When User Control Serves As A Base User Control ?

Jun 4, 2010

I don't think I understand fully how ASP.NET does inheritance of controls.I have a user control, ucBase, which has an asp.net label in the ascx file. Code behind references the label and it works fine during run time if the control is not a parent for another user parent.

If I have another user control, ucChild, inheriting from ucBase, the label in ucBase's code is always null. ucChild has no controls in its ascx fileThe server controls (like the label) needs to be declared in the ascx file and not created programmatically.What needs to be done for ucBase to see its own controls when it's a parent user control?

View 1 Replies

State Management :: User Control And ViewState/ The Parent Page Is Not "synchronized"?

Jun 15, 2010

I make a user control with DataList to expose pagining . I choose to use ViewState to save the state of pagining (TotalItems , CurentPage etc) , but it seems the view state of the parent page is not "synchronized" with the one from user control . It's basically the same situation like the example :

I have a dummy user control :

"<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>"

and the code -behind

"public partial class WebUserControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)[code]...

The question is, why do I have to click twice to get the right result ...3 . I mean at the first click I still get the value 0 .

View 4 Replies

DataSource Controls :: Error Accessing SQL Server Db From User Control In SharePoint

Jan 15, 2010

I'm developing an ASP.NET user control in VS2008 that writes to a SQL Server 2005 database. I've published the control to a SharePoint 2007 MOSS page using the SmartPart addon. The control consists of a few text fields and a submit button that writes the contents of the text fields to the database. When I test the control in the Visual Studio debugger, it works fine. When I try to submit data from the SharePoint page, I get the error shown at the end of this post. Last time I saw this, it was a database permissions error, but I've granted my site's default application pool read/write access to my database. Does anyone have any idea what else the problem might be? Also, how can I double-check the credentials that the SharePoint page is using to access the database, since I still suspect that this is a permissions issue?

[ERROR TEXT FOLLOWS]
Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
ConnectionHandler.ClientDataConnect() +103
ClientData.ClientData.Page_Load(Object sender, EventArgs e) +1426
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +41
System.Web.UI.Control.OnLoad(EventArgs e) +131
System.Web.UI.Control.LoadRecursive() +65
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Control.LoadRecursive() +190
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2427
Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

View 2 Replies

Vb.net - Add Dynamic User Controls BASED ON ViewState - BUT Before LoadViewState Phase

Jan 27, 2011

Setup:

My page has a drop down whose values are dynamically populated. Based on which item is selected, a number of TextBoxes are dynamically created during runtime.The user then fills in information into the textboxes and clicks a submit button.

Problem:

After postback from the submit button, I need to again dynamically create the TextBoxes during Page_Init (BEFORE LoadViewState) so that after the ViewState loads, my Button_Click event can save/do whatever with the user input. PROBLEM is, I cannot recreate the textboxes based on the selection in the dropdown, because the dropdown hasn't been "selected" yet by LoadViewState.

SO, how can I read from the view state, create my textboxes, then let the viewstate populate the textboxes, and then the Button_Click will use the values??

The one thing I've attempted is to override the LoadViewState function so that I can read from the view state, create the boxes, and then load the viewstate again. This did NOT work, because the debugger never seemed to hit my overridden function.

[code]....

View 1 Replies

How To Access Php Javascript Object In Asp.net User Control

Apr 14, 2010

I have a website in php which is using 4 frames(top, left, middle and right). The middle frame contains the web user control coded in asp.net. Now, in the right frame( which is coded in php ) some javascript contains the id of the items selected in right frame. I need to get those ids to the middle frame on asp.net user control.

View 1 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object Repeater Control

Apr 21, 2010

can you please help me to brainstorm the possible causes of this error. I've got a paged repeater with localisation bound programitcally to an sqldatasource using a stored proc. I can post code if needs be but it's rather long. I'm looking for typical causes of this error + will make note for future reference!

erver Error in '/WebSite4' Application.

Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

[Code]....

Line 233:Line 234: Repeater1.DataSource = PagedResultsLine 235: Repeater1.DataBind()Line 236: doPaging()Line 237: End Sub

View 9 Replies

Web Forms :: Unable To Maintain Viewstate Of Dynamically Added User Controls

Apr 24, 2010

I have ONE <asp:Button ID="btnAddUC" runat="server" ......./> and ONE <asp:Table ID="tblUC" runat="server"...> on my page. User clicks on btnAddUC, user control is added to the page [user can add 'n' user controls to the page]. here I have no problem, adding user controls to the page on user clicks.

My user control has ONE <asp:DropDownList ID="ddlItems" runat="server" ......./> and ONE <asp:CheckBoxList ID="chkItems" runat="server"..../>. I am exposing "ddlItems" by public method, "chkItems" is not exposed. "chkItems" is binded on SelectedIndexChanged event of "ddlItems".

Execution scenario:

User adds user control to the page, select item from the "ddlItems" ( Note: "ddlItems" is exposed by public property ) , "chkItems" is populated ( using ddlItems.SelectedItem.Value ) . User checks some checkboxes in "chkItems" and then decide to add one more user control. When the second user control is added to the page, checkboxes in the first usercontrol lose their state and apeears unchecked (NOTE: user checked some checkboxes and then added another user control).

I want to put checked beckboxes index in session ( Before another control is added, which event I should use, because at LOAD event there is nothing).

I was able to restict SelectedIndexChanged event to only that user control whcih generated it (checking _EVENTTARGET)

View 9 Replies

Forms Data Controls :: Object Reference Not Set To An Instance Of An Object In Nested Repeater Control Of CheckBox List ...

Sep 24, 2010

[Code]....

I am getting error of in Foreach loop

[Code]....

How to resolve this situation or any other alternative to cum out of this problem.

View 6 Replies

C# - Object Serializable For AJAX - WCF And ViewState

Jun 30, 2010

consider the following class and struct

public class Entity {
public IdType Id {get;set;}
public string Data {get;set;}
}
[TypeConverter(IdTypeConverter))]
public struct IdType {
... any data ...
}

The IdTypeConverter can convert the IdType struct from and to string. Now, what I want is this class to be serializable for AJAX, WCF and ViewState. The senario could be a WCF web service which provides as array of Entity[] to a DataSource. And a custom control which binds to the datasource, saves this class to it's ViewState and sends the data to client side code. This could be achieved easily by simply adding a [Serializable] attribute to all serialized types. But I don't want the IdType to be serialized, but to be converted to a string. Thus the JSON representation should be

{ 'Id'=>'StringRepresentationOfId', 'Data'=>'foo' }

This would analogously be the optimal serialization for WCF and ViewState. Another solution would be to write another class

public class JsonEntity {
public JsonEntity(Entity from) {
Id = from.Id;
Data = from.Data;
}
public string Id {get;set;}
public string Data {get;set;}
}

and use this for JsonSerialization. But I don't like this, because this would imply that the control which is sending the data to the client knows about the Entity type. The actual question is: Is it possible to customize JsonSerialization with attributes without breaking WCF and ViewState serialization? DIT: An answer like "That' impossible" would satify me, since I'd stop trying.

View 2 Replies







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