locked
Disabling View state RRS feed

  • Question

  • User-1812261665 posted

    Hi, I have a drop down in aspx page , i want to disable view state of that drop down with out affecting dropdownselected event .

    reason of disabling view state of dropdown is because it loads thousands of options which makes that page heavy..

    Any help appreciated

    Sunday, April 17, 2011 10:14 AM

Answers

  • User533502567 posted

    I have a drop down in aspx page , i want to disable view state of that drop down with out affecting dropdownselected event .

    SelectedIndexChanged event will fire, even if you disable the Dropdown viewstate.

    But the event is meant to fire whenever the index changes and theres a postback. Since you have viewstate off, the event will fire on each postback.(on Button click etc..) 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 18, 2011 4:12 PM
  • User1618479829 posted

    make enable view state property of dropdownlist to false. if you do this

    1) the selection made by the user will not retained.

    2) need to bind data source every time page loads.

    work around for this declare a hidden variable and set the selected value by user using JS ,then on the page load check for any value change, if

    value changed then call dropdown selected index change event explicitly

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 24, 2011 12:49 PM

All replies

  • User761909039 posted

    You can always enable or disable Viewstate at every control level. You just need to set EnableViewState="false " or ViewStateMode="Disabled"  in that dropdown

    <asp:DropDownList ID="dropdown" runat="server"  EnableViewState="false" ViewStateMode="Disabled"></asp:DropDownList>

    Sunday, April 17, 2011 12:57 PM
  • User-519136805 posted

    I would suggest you to cache DDL rather than disabling viewstate of it. becoz disabling viewstate might cause problem when you try to access values in it during postback. Hope this will help !!!

    Monday, April 18, 2011 4:52 AM
  • User533502567 posted

    I have a drop down in aspx page , i want to disable view state of that drop down with out affecting dropdownselected event .

    SelectedIndexChanged event will fire, even if you disable the Dropdown viewstate.

    But the event is meant to fire whenever the index changes and theres a postback. Since you have viewstate off, the event will fire on each postback.(on Button click etc..) 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 18, 2011 4:12 PM
  • User-481631678 posted

    Disabling viewstate will not effect any of the events however after every postback, you have to re-bind the dropdown with datasource.

     

    I recommend you that if you are populating dropdown with thousands of records why don't you try replacing it with autocomplete textbox. They are quite fast in terms of speed and page size. Here are some samples:-

    http://www.asp.net/ajax/ajaxcontroltoolkit/samples/autocomplete/autocomplete.aspx

    http://www.devbridge.com/projects/autocomplete/jquery/

    Tuesday, April 19, 2011 2:09 AM
  • User1618479829 posted

    make enable view state property of dropdownlist to false. if you do this

    1) the selection made by the user will not retained.

    2) need to bind data source every time page loads.

    work around for this declare a hidden variable and set the selected value by user using JS ,then on the page load check for any value change, if

    value changed then call dropdown selected index change event explicitly

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 24, 2011 12:49 PM