Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Save WebControl object In viewstate

hai
when i tying to save the webcontrol object in a viewstate i am getting a error like
"must be marked as Serializable or have a TypeConverter other than ReferenceConverter to be put in viewstate "
any idea
[227 byte] By [Bhargava] at [2007-11-11 7:18:29]
# 1 Re: Save WebControl object In viewstate
on top of your webcontrol class add the attribute [Serializable] see if it helps.. Objects to be saved in the view state or when used in session in state server mode have to be serialized
srinivas_s at 2007-11-11 23:13:47 >
# 2 Re: Save WebControl object In viewstate
i did it but there is no change
Bhargava at 2007-11-11 23:14:47 >
# 3 Re: Save WebControl object In viewstate
What webcontrol is this .. From what you mention I am guessing its a custom webcontrol? Another thing during implementation we normally dont put the control itself in viewstate.. can you detail the problem more.. as to why you are doing this
srinivas_s at 2007-11-11 23:15:52 >
# 4 Re: Save WebControl object In viewstate
hai srini,
this is what my problem,

i am creating a simple datagrid control ,after rendering, the control should work from javascrip for adding row and deleting rows.
finaly total changes in grid needs to update
Bhargava at 2007-11-11 23:16:58 >
# 5 Re: Save WebControl object In viewstate
You do know there are events for edit update and delete row in the datagrid already ..
If you are using the dataset to bind to the grid, you can add it to the view state in the page load and then play with it in your grids event handler and when all the updates on the dataset is done you can update your database with the changes.I am mentioning this because it is the data bound to the grid you want in the viewstate not the grid itself.
srinivas_s at 2007-11-11 23:17:57 >
# 6 Re: Save WebControl object In viewstate
My ideas on solving the problem would be

to add a row you could use the AddNew row method on the dataset table with blank values and then bind the grid again to the dataset , then change the edititemindex to the row index added will give you the same as edit but with blank input controls

I guess you should use a popup window to add a row and when the data is entered and submitted you can refresh the parent window with javascript from the popup window on close of the window. This popup window can also be a frame in the same page at the bottom of the grid thats your choice if you do not want popup windows

You can render add button for each row in the itemcreated event of the datagrid and have a javascript function added to there onclick attributes.

For delete it doesnt make sense for javascript to be used as you have to do a postback anyway

Update is the same as the addnewrow not very different

Hope this helps
srinivas_s at 2007-11-11 23:18:56 >
# 7 Re: Save WebControl object In viewstate
hi sri

thanks,

here the problem is
if datagrid is having hevy load of data that time if i select a row it self will take big fliker to reload the page.to avoid those thing i want to deal with javascript.
if i do this final updation only will take big refresh ment.remaining thing i will do it here from client
Bhargava at 2007-11-11 23:20:00 >
# 8 Re: Save WebControl object In viewstate
I understand that a datagrid with some heavy data can be really slow. The flicker you are talking about is the post back. This is exactly where custom paging comes into play and makes the grid efficient, try to query records you need on a page only do not try to hold information that is not required for a page in viewstate

There is an article on Code project on custom paging see if thats a route that helps.
As for javascript its going to be a nightmare for you to access the controls in the columns of the grid programmatically because the grid renders the child controls and there ids. In javascript you either need the name or the id of the element to get the instance so think about it..
srinivas_s at 2007-11-11 23:20:58 >
# 9 Re: Save WebControl object In viewstate
thans sri
i will go tru that
Bhargava at 2007-11-11 23:22:02 >