0
votes

I have question regarding ViewState I want to disable a ViewState From CodeBehind because the Control Which I have used in my Application which can be used for many clients so it's not possible to Disable ViewState from UI side.

I have a Control like

<%@ Control Language="C#" ClassName="allrealTimeHorizonAndChartControls" Inherits="QFlife.IrApps.SM6.TimeControl" %>
<div style="float:left; width: 570px; border-top:1px solid #EDEDED;" class="borderright">
    <div style="float:left; width:570px">
        <input ID="Submit1" class="update_button" type="submit" value="<%= IRAppMgr.Translate("command_update") %>" />
    </div>
    <%--<div class="HelpButton" style="float:left; width:285px">
        <% string culturename = ""; %>
        <% culturename = IRAppMgr.UiCulture.Name; %>
        <a class="help" target="_blank" href="http://ir.quartalflife.com/qmip/qsm/public_html/sm6help/navigation_en-US.jsp">
            help
        </a>
    </div>--%>
</div>
 <asp:ObjectDataSource ID="SharesDS" runat="server" DataObjectTypeName="Qfx.DataClasses.Config.Option"
        SelectMethod="SelectOptions" TypeName="Qfx.Bases.data.DataManager">
        <SelectParameters>
            <asp:ControlParameter ControlID="ClientMarker" Name="appConfig" PropertyName="Config"
                Type="Object" />
            <asp:ControlParameter ControlID="ClientMarker" Name="client" PropertyName="Client" />
            <asp:Parameter Name="selection" DefaultValue="shares" />
        </SelectParameters>
    </asp:ObjectDataSource>

I want to Disable ViewState Only for ObjectDataSource, Now I want to do Something on my Qfx.Bases.data.DataManager Class so it shoule be apply for all clients .

My DataManager class look like

     public class DataManager
     {
        //All Code Goes Here
     }

I have tried below menioned code

        Page P = HttpContext.Current.Handler as Page;
        P.ViewStateMode = ViewStateMode.Disabled;

but I got HttpContext.Current.Handler is null can anyone please suggest me how could I achive this.

1
Why don't you just disable the ViewState in the User Control? There should be a DisableViewState property you can set in the header. - Philip Pittle
I have to change 10000 pages for it that'y I want to change it from code behind - Dhaval Patel
Not if you change it in the User Control definition. Unless you have 10,000 different User Controls? - Philip Pittle
I want to Disable ViewState Only for ObjectDataSource Only - Dhaval Patel
Ahhh ok. In that case it might be easier to create a wrapper of ObjectDataSource and disable ViewState from that control. Then update your ascx files to use your CustomObjectDataSource - Philip Pittle

1 Answers

0
votes

See here: http://www.c-sharpcorner.com/UploadFile/rohatash/various-ways-to-disable-viewstate-in-Asp-Net-4-0/

It gives an example for disabling view state for the entire page by adding an OnInit event and using this.EnableViewState = false. You can do the same for a single control.