.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

viewstate - so lost :(

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net


I will try to be quick and to the point. I have a calendar control who's DayRender event is used to query a database for events that match the day so that the background can be changed to a different color, *and* I add an entry to a dictionary<string,string> viewstate object... like:
((dictionary<string,string>)viewstate["dateToEventTracking"]).Add(e.Day.Date.Date.ToShortDateString(), sEventNameFromDB);

the viewstate object is first initialized on page_load in condition of *not* postback with something like:

Dictionary<string, string> DateToJobNumbers = new Dictionary<string, string>();
            ViewState["DateToJobNumbers"] = DateToJobNumbers;
Dictionary<string, string> dateToEventTracking = new Dictionary<string, string>();
ViewState["dateToEventTracking"] = dateToEventTracking;

this same code also runs in the visibleMonthChanged event to re-initialize it with a fresh new empty object, since the whole purpose of this is to tr

View Complete Post

More Related Resource Links

Composite Control which contains arbitrary content defined in .aspx of parent and thier ViewState


I want to write own control which can contain other. And I want to define content of the control in the .aspx file where the control is defined. I have written such control. But now I have issue with ViewState of inner controls of my control. The following samle illustrates the issue: I defined two asp:DropDownList ID="ddl1" and ID="ddl2" One of them is inside of my control and other is outside. When posback is occurred asp:DropDownList ID="ddl1 loses state and becomes empty. How to say ASP.net to store state of inner controls defined by this way?


<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="DynamicControls.Controls.MyControl" %>

<div class="box">
    <div class="Header-Left">
        <div class="Header-Right">
            My Control
    <div class="Content">
        <asp:PlaceHolder ID="contentPlace" runat="Server" />

Memory Lane: Rediscover the Lost Art of Memory Optimization in Your Managed Code


Managed applications rely on the garbage collector in the .NET Framework to allocate and clean up memory. The little CPU time spent performing garbage collection (GC) is usually a fair trade-off for not having to worry about memory management. But for applications in which CPU time and memory are precious resources, minimizing the time spent garbage collecting can greatly improve application performance and robustness. Find out how to manage memory all over again.

Erik Brown

MSDN Magazine January 2005

EntityDataSource Where Clause in ViewState?



I have ListView/DataPager on the page that I use together with an EntityDataSource, because I want to filter the results, I programmatically set the Where-property and the WhereParameters of the EntityDataSource.

But: After the Paging-Postback the Value for Where is gone (empty string) whereas the WhereParameters are still there. Isn't the where value saved in ViewState as well? Can I change this behaviour?

Thanx, S.

Data lost on submit


Dear Experts,

I have a modal popup and a GridView in it. The GridView is populated programmatically, i.e. I use .DataBind(). I can enter data into some of the GridView's controls. After I press Submit, I expect to do something with the entered data. But in the button press handler, the GridView is empty. I realize that I have to DataBind() again in the handler, but how can I preserve the data the user enters?


Custom controls and ViewState management issue



I want to know that when we create custom controls, then is there State Management through ViewState done automatically or we have to handle it explicitely ?Since i have created Custom Controls that is behaving as if it is not maintaining its state on PostBack.

session lost problem


hi there,

i have an application that uses sessions.

i have set at the web.config: 

<forms loginUrl="Default.aspx" protection="All" timeout="30" name=".ASPXFAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="Default.aspx" cookieless="UseCookies" enableCrossAppRedirects="true"/>

and at the global.asax.vb

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
        Session.Timeout = 30

end Sub

and at default.aspx.vb

Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
        Session("userName") = Login1.UserName
        Session.Timeout = 30 ' minutes of session '

    End Sub

At a local iis on windows xp works fine,

but when i publish it at the webserver i am redirected to the default page after about 30 sec!!!

any ideas?


WSS 3.0 Content Type - Lost data for Titles


We are running WSS 3.0 SP2 on server 2003.  Recently, we lost the "Titles" for all content types for documents.  Our system Content Type for Document is set up to require this field to be completed on all documents that is uploaded.  Our system would automatically enter in by default the name of the document in the "Title" field it no longer does this for the user.  The user must now enter in manually the "Title".  How do I get it to enter in the "Title" using the document file name automatically?

Below is the way the setting page for Site Content Type: Document looks like.  (I tried to recreate it since I could place a screen shot in the box)

Site Content Type Information
Name:  Document
Descriptiong:  Create a new document.
Parent:  Item
Group:   Document Content Types

Name, Description, and group
Advanced settings
Workflow settings
Delete this site content type

Name                 Type                     &nb

Contact Selector - Form tab index is lost after selector resolves names on blur


I'm working with an InfoPath2007 form developed to be filled-out through the browser on a SharePoint 2007 site, and I'm testing using Internet Explorer 7.  It's a straight-forward form, with a number of text fields and two Contact Selector controls.

The issue I'm encountering is with the Contact Selector control, where if the actor only enters a partial name into the text-field and then TABs away from the control the form will perform its auto-postback to look-up and resolve the partial name (showing the name resolution dialog is necessary), and afterward the actor's cursor is focused on the next field in the form.  The actor can type text into the focused field, but any subsequent pressing of the TAB key returns the actor's focus to the browser's ADDRESS bar, which is incorrect as it should proceed to the next field in the form.  I understand that the Contact Selector needs to perform its postback to perform the name resolution (so that there is no way through the InfoPath form designer to disable postbacks for the control), but why does the browser not know how to continue the TAB order of the fields on the form even when a field has focus?

Adding table to a page, but the format lost when I use clear border



I added a table to a page, by default, the table layout is the light border. So, I add my content and the vertical align seems to set to the top. But when I changed it to clear border, the content of the table will set vertical align to center. Is there a way to change this back to top align but with the clear border. I don't think I can do this by what is available in the ribbon. Please advice.

Changing aspx page causes session data to be lost...


Strange but true. Any ideas what might be causing this?


viewstate in a custom control

I am having issues with a simple custom control that I created by subclassing the hyperlink control.

I wanted to create a control called BackLink that would automatically grab the referring url to the page when it first loads the page. and on postbacks it would continue to use the initial value

I am able to capture and set the navigateurl property when the containing page first loads just fine but if the page submits to itself, the control loses its navigateurl value.

I have the enableviewstate property set in the aspx page but it doesn't seem to want to keep its viewstate

Am I missing something? Do I have to manage my own ViewState?

here is my code

public class BackLink : System.Web.UI.WebControls.HyperLink

public BackLink()
this.Text = "<< back";

protected override void Render(HtmlTextWriter output)
if (this.Page.IsPostBack == false)
//save back url
Uri _backUri = this.Context.Request.UrlReferrer;

if(_backUri != null) this.NavigateUrl = _backUri.PathAndQuery;

else this.NavigateUrl = "/";

Sharepoint farm lost a server... How to proceed?


Had a Sharepoint farm I inherited that was running on ____ hardware in a ____ setup- raid controller failed, and the rack was setup so that I have to down 15 servers that might not come back up, just to get at the server... Complete, unrecoverable failure. This server was a member of our Sharepoint 2007 farm, and had Reporting Services on it. There are a lot of little pieces that are still referenced in the Central Configuration. I removed the server forcibly, and need to know next steps, specifically:

1. I tried to move Reporting Services to another server, but I get an error in the Grant Database privileges that I cannot connect to the Report Server's WMI Provider. I created a SPN on a DC, forced a replication a few hours ago, and still no luck. Any Advice?

2. How do I fix all the little things that reference that server? Anytime Sharepoint initiates a web page to Central Administration, it tries to use that server address.

I think the failed server was running SQL 2008 or SQL 2008 R2, and the server I am moving this to is SQL 2005 SP2. I have installed the correct Reporting Services for Sharepoint. Have I missed something?

Time is of the essence because management relies on Reporting Services and I am under a great deal of pressure to fix this. I appreciate any help I can get.



Connection to NAS lost after restart

We are running MS SQL 2005 on Windows Server 2003. We are storing one of our MS SQL databases on a NAS device. It is working quite well except for one minor problem. Whenever the MS SQL machine restarts, MS SQL is not able to access the NAS device. To fix, all I have to do is restart MS SQL (not the machine, just the database server) and then it works fine again until the next time the machine restarts. It is as though, when the machine is starting, MS SQL starts before the machine is ready to do TCP/IP file sharing. I suppose the solution is to delay the starting of MS SQL until the machine is ready to network. I would appreciate suggestions for introducing such a delay.

Viewdata lost in handleerror

Anybody know why my viewdata is lost when HandleError filter kicks in? Below is the question posted on SO by somebody else but the solution looks overly complicated , is there a better way? http://stackoverflow.com/questions/1794936/how-do-i-pass-viewdata-to-a-handleerror-view

POST from html form viewstate problem

<p> Hi all, I have a website where people need to pay for a specific download (.pdf file). After they payed they get the download(A). My payment-provider can do a HTML-Postback to the site i want, for each succesfull payment. So the idea is that if someone payed, they do a postback to my server with a couple of parameters, so i can know that that specific email address has payed, and they get the download. I tested localy with a .html file on my desktop to postback a set of parameters to my local asp.net website. But in ONLY works if i include the __VIEWSTATE in my html file. And i cant get rid of the viewstate in my HTML of the aspx page. >test.html: <html><head></head><body> <h1>Dit is een test</h1> <form id="form1" action="http://localhost:25659/WebForm1.aspx" method="POST"> <input id="Button1" type="submit" value="submit!"/> 'IT ONLY WORKS IF I INCLUDE THE NEXT LINE: <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNGRk" /> </form></body></html> Has anybody an idea to acomplish my goal? Maybe i can get some info about the postback in my global.asax? or create a HttpHandler for .html files? Anyone?   Thanks in advance, Vincent   </p>

How to avoid viewstate in page load event??

Hello Everyone, Here Is my scenario,I haveMaster Page -> ASPX page -> User ControlUser control page is contains all dynamic bind controls (e.g Repeater) depended on ASPX Page (Only one parameter say ItemNo) The problem is, if I bound user control on page load event with passing respective parameters then it's create to much view state (I checked source file and it's almost 1.5 MB) In other way if I put one textbox, and a command button and I pass required parameter on button click and load the control then page size is ok (I checked and it's  < 500KB) So is it any way I can reduce my page/state size??
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend