viewstate

Keeping Data in GridView after PostBack

蹲街弑〆低调 提交于 2019-11-29 15:27:13
I have a GridView which is associated with an SqlDataSource . When I click a Button , I change the SelectCommand and then I use DataBind to update the GridView . After PostBack, I want the latest Data to Remain, I don't want the GridView to be loaded by the original SelectCommand . I know this is done by something called ViewState , but I didn't manage to implement it in the right way. I tried both EnableViewState="true" and EnableViewState="false" on the Grid itself, with no luck. Code <asp:GridView ID="GridView1" ...... DataSourceID="UsersSource" > <asp:SqlDataSource ID="UsersSource" ...

.net ViewState in page lifecycle

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 14:25:47
I have a page containing a control called PhoneInfo.ascx. PhoneInfo is dynamically created using LoadControl() and then the initControl() function is called passing in an initialization object to set some initial textbox values within PhoneInfo. The user then changes these values and hits a submit button on the page which is wired up to the "submit_click" event. This event invokes the GetPhone() function within PhoneInfo. The returned value has all of the new user entered values except that the phoneId value (stored in ViewState and NOT edited by the user) always comes back as null. I believe

Determine size of ASP.NET page's viewstate before serving page

本秂侑毒 提交于 2019-11-29 14:21:34
What ASP.NET page lifecycle event can I write code in to determine the size of the viewstate that being sent out? Also, is it possible to determine the size without parsing through the rendered HTML (like a property on the page object) or is parsing the only way? What I'd like to do is log the sizes, specifically if they cross a certain threshold. You can go on the function that is going to writing the viewstate, the SavePageStateToPersistenceMedium . This is the function that also used to compress viewstate... For example... public abstract class BasePage : System.Web.UI.Page { private

Accessing controls added programmatically on postback

限于喜欢 提交于 2019-11-29 12:11:06
On postback : How can I access ASP.NET controls in my code-behind file, which are added programmatically? I am adding a CheckBox control to a Placeholder control: PlaceHolder.Controls.Add(new CheckBox { ID = "findme" }); Controls added in the ASPX file are showing up fine in Request.Form.AllKeys except the ones I add programatically. What am I doing wrong? Enabling the use of the ViewState on the controls does not help. If only it was that simple :) ika You should recreate your dynamic control on postback: protected override void OnInit(EventArgs e) { string dynamicControlId = "MyControl";

Which controls have ViewState maintained?

时光总嘲笑我的痴心妄想 提交于 2019-11-29 11:32:11
I am trying to wrap my head around the control infrastructure to understand which ones ASP.NET maintains view state for. There are these regular HTML controls ex: <input type="radio" checked="checked"/> -> I understand these do not have viewstate Then there are HTML controls with runat="server" <input type="radio" checked="checked" runat="server"/> -> Does the viewstate get maintained between postbacks? Then there are ASP.NET controls <asp:TextBox id="txtMyText" runat="server"/> -> I understand these do have viewstate We have a few custom controls that inherit HtmlTextBox <myPrefix:myTextBox

How can I re-instantiate dynamic ASP.NET user controls without using a database?

主宰稳场 提交于 2019-11-29 07:36:04
I'm currently working with a part of my application that uses Dynamic Web User Controls and I'm having a bit of trouble figuring out the best way to re-instantiate the controls on postback by using ViewState or some other method that doesn't require me to query a database on each postback. Basically what I have on my page is a user control that contains a panel for holding a variable amount of child user controls and a button that says "Add Control" whose function is pretty self explanatory. The child user control is pretty simple; it's just a delete button, a drop down, and a time picker

Getting asp.net to store viewstate in the session rather than bulking up the html

混江龙づ霸主 提交于 2019-11-29 07:07:54
I'm trying to get asp.net to store viewstate in the session rather than bulking up the html. Now i've read that asp.net comes with the SessionPageStatePersister which can be used instead of the default HiddenFieldPageStatePersister to do this. I was wondering how i go about dropping it in? This is what i've got so far: I think i need to create a PageAdapter that returns a SessionPageStatePersister from its GetStatePersister method, and somehow get the page to use this pageadapter. But Page.PageAdapter only has a getter, so i'm not sure how you set it. See the 'remarks' heading here: http:/

What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?

做~自己de王妃 提交于 2019-11-29 07:07:15
问题 What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState? 回答1: If you really want to understand ViewState (not just what it is used for), then you may want to read this fabulous article (which I, unfortunately, am not the author of :-). Beware, though, it is a bit dated, but still a very good read. 回答2: View state is a kind of hash map (or at least you can think of it that way) that ASP.NET uses to store all the temporary information about a page - like what options are

Why does __VIEWSTATE hidden field gets rendered even when I have the EnableViewState set to false

别等时光非礼了梦想. 提交于 2019-11-29 06:57:38
I saw that __VIEWSTATE field gets rendered even though I have set the EnableViewState="false" at the page level. This field is not rendered if I remove runat="server" tag for the form element. Can somebody please explain this? The __VIEWSTATE field is also used to store control state, which is not optional. Furthermore, the information contained in the view state is used to validate the postback, if I'm not mistaken (and validation is enabled, which is the default). So as long as you have the form with runat="server", you'll have a viewstate field. However, you should notice a much smaller

Validation of viewstate MAC failed [duplicate]

纵然是瞬间 提交于 2019-11-29 06:34:57
Possible Duplicate: Setting ViewStateUserKey gives me a “Validation of viewstate MAC failed” error I have applied the solutions of the posts on StackOverflow but they did not work out for my problem. The details of the problem is: 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. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more