C# - ViewState Is NULL In Page_Load But Not Postback?
Jun 4, 2010
I've got a weird problem with a NullReferenceException on a high traffic website my company hosts. The exceptions are logged with full stack-traces but I am unable to reproduce it.The exception occurs a couple of times a day, for different users, and it's a NullReferenceException thrown in the code block below:
protected void Page_Load(object sender, EventArgs e)
{
...
if (!Page.IsPostBack)
{
...
this.ViewState[StaticClass.StaticStringProperty] = StaticClass.StaticIntProperty; // this is the line the exception occurs on
...
}
}
The only place I can figure that a NullReferenceException would be thrown is if ViewState is NULL, but I've never known that and can't find any reason why this would be the case in a Page_Load that isn't a postback.StaticStringProperty and StaticIntProperty are both initialised, static properties of StaticClass.
StaticStringProperty is defined as:
public const string StaticStringProperty = "IdFromClient";
Does anyone know how this could happen, or any other reason why a NullReferenceException would be thrown on the above line?
EDIT.As requested, the full stack-trace for the error is as follows. Line 54 is the line I've highlighted above.
at MyCompany.MyApplication.Appliance.Page_Load(Object sender, EventArgs e) in C:Documents and SettingsshellamaMy DocumentsMyApplicationAppliance.aspx.cs:line 54
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)[code]....
View 1 Replies
Similar Messages:
Apr 18, 2010
Im currently experincing some difficulties with the viewState. The scenario is that i have a datagrid that has a column of buttons that when pressed will store a value in the viewState. I have already done this on one occasion in the same page, but for some reason the second item in the view state is always returning null, even when i hardcode in a number in before the postback. Im at a loss as to why this is happening, anyone expericened this and know what is wrong.
EDIT: Ive found out the cause, Its due to when you click a button in a data grid it does the postback code first, then fires the event handler, so of course the view state would be empty as it is coded to be set in the event handler for the button click. Is there any way to avoid that? So the event code is fired before the postback code?
View 5 Replies
Apr 20, 2010
I've been trying solution I've found oline all day trying to get a GridView to Display its Header when its datasource returns 0 rows. So far, nothing has worked for me. I did come across an interesting bit of code, but I'm having a spot of bother with something else preventing me from getting it to work.
[Code]....
View 4 Replies
Jul 5, 2010
asp.net 4.0 vs2010
I'm developing an asp.net model -view-presenter (MVP), and to my surprise i see that when I click on the linkbutton in the window the Page_Load event is fired again. Is that normal? I'm used to webforms where we could just do a if (!Page.IsPostBack) if statement in the Page_Load. I did that but then no action happend when I clicked the linkbuttons in the window.
View 2 Replies
Feb 18, 2010
Im using intelligencia urlrewriter as my url rewrite module. I have one very strange problem which only occurs when an url is rewritten but to make it more fun, not on all rewritten pages. Edit: Forgot to tell you what's the problem boing boing. the problem is that my Page_Load event gets fired 2 times.his is how my form rewrite adapter looks like:using System;
using System.Web.UI;
using System.Web;
using System.Web.UI.WebControls;
[code]...
View 3 Replies
Mar 17, 2010
I have a page with a drop-down. Based on the selection in the drop-down, data gets loaded and populates a RadGrid. I am using a custom user control for the EditTemplate, so I can't use radGrid.DataBind(). Instead, I have to use radGrid.MasterTableView.Rebind() in association with a NeedDataSource event handler.
My problem is that when I load the page initially, I populate the drop-down and automatically select a value (first item in the list) which triggers the databinding on the RadGrid. I can step through the code in debug mode and see that the grid is being populated with data, but when the page displays, it doesn't get rendered. When I then manually choose an item from the drop-down, which triggers the same grid databinding code, it displays properly the second time.
How do I get it to display the grid the first time the page loads?
View 2 Replies
Mar 30, 2010
During Asynchronous postback (Ajax) will Page_PreInt() ,Page_Init(),Page_Load() events fire again?
View 1 Replies
Feb 5, 2011
developing a photogallery using datalist and custom numeric pagination.
I have assigned the CurrentPage Index of the PagedDataSource object by requesting "pid" value from QueryString .
On the pageload i hit the database once and store the filenames in ViewState but..
But the ViewState becomes null when the page is posted back with new query string value.
View 2 Replies
May 12, 2010
well what i want to find out is how can i figure out if some change occurd in page when postback , i mean when the first state of the page hahe any changes after postback . I thought maybe somehow to compare viewstaes but i can not find out how can i do that.
View 13 Replies
Apr 8, 2010
I have a grid with rows of data, but the page will fail have several postback. I check it with fiddler and find that view state expands 2-3 times after each post back.
The thing I did to trigger the post back is searching and sorting. I am not sure how it happens.
View 2 Replies
Feb 9, 2010
I want to be able to find the old value of a asp.net control (textbox, checkbox etc) without relying on events (e.g. OnTextChange event). Something like "someTextboxControl.OldText" would be perfect! I imagine that it is stored in the viewstate and need to somehow get at it via a custom control.
View 2 Replies
Apr 13, 2010
I'm having trouble with a simple radio set of two radio buttons (I don't want to use a RadioButtonList [RBL] because RBL doesn't allow child controls, and in my case, if you select one option, I want to enable a textbox next to the button; yes you could hack this with jQuery to move the textbox, but that's dirty!). I would check one, submit the form (either explicitly or through AutoPostBack), and the CheckedChanged event would never fire. When the page was reloaded, both buttons would be unchecked, regardless of their initial state on non-postback load or the state before form submission.
form id="form1" runat="server" enableviewstate="true">
<div>
<asp:RadioButton ID="foo" Text="foo" runat="server" AutoPostBack="true" OnCheckedChanged="rbChanged" Checked="true" GroupName="foobar" EnableViewState="true" />
<asp:RadioButton ID="bar" Text="bar" runat="server" AutoPostBack="true" GroupName="foobar"
OnCheckedChanged="rbChanged" Checked="false" EnableViewState="true" />
[code]...
View 2 Replies
May 4, 2010
Is there a reliable method for viewing the size of the viewstate on any given postback?
View 3 Replies
May 3, 2010
I am creating a simple string of values that get added to a label after a post back. I am setting the values thorugh ViewState. However, my appended values do not get updated until AFTER the 2nd postback. Example:
On Page_Load the label displays a "0";
If I enter a "1" in the text box and click the button the label still displays a "0";
If I click the button again (the 2nd postback) then my label correctly displays "0,1"; This works for whatever value I enter after. i.e. "0,1,35,hello world", etc.
What I am I missing? Code Below.
.ascx - I left out inherits and codebehind
[Code]....
View 4 Replies
Aug 27, 2010
Is it necessary to reload the viewstate of usercontrols during postback? I want to know in which case viewstate is set by default.
View 2 Replies
May 20, 2010
I'm doing nothing special with session...
I just put some value on button_click event handler and then redirect to another page
like this { Session["key"]="value"; Responde.Redirect("AnotherPage.aspx"); }
And then I try to read Session["key"] on Page_Load of AnotherPage.aspx but it's null!
What can cause this?
P.S. When I use Server.Transfer() instead of Response.Redirect() it works fine.
View 2 Replies
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
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
Sep 10, 2010
I'm reading about the UpdatePanel and how it interacts with controls inside & outside of it.
My understanding is that the usual ASP.Net pipeline takes place when posting from within an UpdatePanel-- Page load etc all fire off as normal-- except when the prerendering stage is reached. In that case the ScriptManager does a final check and only renders those controls within the UpdatePanel and skips the rest. That's my understanding at least.
Sounds good, but for argument's sake let's say I have a TextBox located outside an UpdatePanel. If a postback occurs from within that panel, the TextBox's properties can still be set in the page load method, but those changes will not take effect. (normally; it is possible to postback the entire page from an UpdatePanel)
Is that correct? What happens to that TextBox's ViewState in this instance? Is it updated based on what happened to it in the page load method or is that modification tossed out because it wasn't in the UpdatePanel?
View 6 Replies
Oct 27, 2010
I'm getting some strange behaviour with viewstate being lost on postback for a .net application using Sitecore. I'm assuming it might be some config variable somewhere but I'm new to Sitecore and don't really know where to start looking.
UPDATE: Sitecore has now gotten back to us with an answer. We had recently added the dtSearch module, and AutomaticDataBind was set to true in the dtSearch.config which overrides the setting in the web config. We've now removed it and it works fine again.
I've made a mini test if that might help. It's two usercontrols on one page, both with a repeater. When updating the viewstate gets lost so even if I'm binding the updated repeater again the data for the other one will be lost.
Usercontrol 1:
<asp:Repeater runat="server" ID="Repeater1" OnItemDataBound="Repeater1_ItemBind">
<ItemTemplate>
<li>
<asp:Literal runat="server" ID="Literal1"></asp:Literal>[code]....
what might be going on? Let me know if I need to provide any more information. The most annoying thing is that it was working last week but I have no idea what has changed!
View 2 Replies
Mar 5, 2012
The values are stored in viewstate fr the postback... Does everysubsequent post back increase the viewstate size?
View 1 Replies
Mar 25, 2011
I have a bit of javascript that presents a modal to the user with the rest of the page "grayed out." Pretty common these days. The modal allows you to specify a URL which then uses AJAX to serve and display. What I need is that when the control posts back, it posts back to the parent page, not the modal page. To attempt this, I used javascript to alter the target of the modal page's form element to the parent page's URL. When I try this I get the following error:
Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
This is done locally and as of now, the app will never be on a cluster. I think this has to do with the validation process and .NET doesn't like that I've changed the target. Anyone know a way around this? I really need this to work how I described.
View 1 Replies
Oct 23, 2010
When we disabled the viewstate in gridview its lose value but this case not true with Textbox control why?
View 1 Replies
Apr 19, 2010
I have "n" <tables></tables> on my page and each <table> has One(1) <asp:CheckBox.. Enable ='true"/> and "x" <asp:TextBox Enabled="false"..>. Each Table looks as follows
[Code]....
When I click checkbox, it calls javascript function and enables textboxes (I have added onclick attribute to checkbox). Page also has <asp:Button ...Text="Submit"/> whcih actually grabs the data from the textboxes on the page and send it to the databse. Here is the Onclick event of the <asp"button../>
[Code]....
If the exception is thrown , textBoxes are not reset but on postback textboxes appear as disabled (values are not reset)
So here is what happening on postback when exception is thrown
1) Values are not reset (that is what want)
2) Texboxes appear as Disabled (that is what I don't want on exception, REMEMBER I enable textBoxes using client side script)
How can I keep the textboxes enabled = "true"
View 4 Replies
Sep 8, 2010
I've build a class like this:
[code]....
The values of this class are set at postback by clicking a radiobutton list. Problem however is I don't know how to save this values across multiple postbacks. I thought of using viewstate but I'm not quite sure how to do it with this class.
Maybe I'm missing some important thing here.
Hope someone can point me in the right direction.
View 4 Replies