Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2006, 07:04 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Dynamic List Box Post Back Problem

Hi All,

 I have a page with three list boxes that are linked with Handles
 XXX.SelectedIndexChanged

 The boxes run very smoothly and quickly at first. But after I submit the query with the values from the list boxes with a button click event and the data is bound to the data grid the list boxes take forever to post back with the new values if I want to change their values.

 I've been thinking of trying a work around to actually post to another page for the results of the query but can you think of any reason why this is happening? Here is the code for the first list box. The other two are pretty much duplicates of this one.

Code:
      Sub getAreaID(ByVal FacID As Integer, ByVal RuleID As Integer)
          Dim SQL As String = "SELECT Areas.AreaID, Areas.AreaName FROM Areas
 INNER JOIN Facilities ON Areas.FacID = Facilities.FacID WHERE
 Facilities.FacID = " & FacID & "  ORDER BY Areas.AreaName ASC;"
          Dim oDA As New SqlDataAdapter(SQL, _oConn)
          Dim oDS As New DataSet
          oDA.Fill(oDS)
          ddlAreaID.DataSource = oDS
          ddlAreaID.DataTextField = "AreaName"
          ddlAreaID.DataValueField = "AreaID"
          ddlAreaID.DataBind()
          ddlAreaID.Items.Insert(0, New ListItem("All", 0))
          ddlSubID.Items.Insert(0, New ListItem("All", 0))
          ddlLocID.Items.Insert(0, New ListItem("All", 0))
          btnAdd.Visible = False
          grdInventory.Visible = False
      End Sub
 
      Private Sub ddlAreaID_SelectedIndexChanged(ByVal sender As Object, ByVal
 e As EventArgs) Handles ddlAreaID.SelectedIndexChanged
          If ddlAreaID.SelectedValue = 0 Then
              btnAdd.Visible = False
          End If
          ddlSubID.Items.Clear()
          ddlLocID.Items.Clear()
          getSubID(ddlAreaID.SelectedValue, _RuleID)
          grdInventory.Visible = False
      End Sub


Thanks,
Richard

  #2 (permalink)  
Old March 1st, 2006, 03:28 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Added this to the page and it seems to have resolved the problem. Now the page posts back to refill the list boxes immediately.

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        Dim dgi As DataGridItem
        For Each dgi In grdInventory.Items
            dgi.EnableViewState = False
        Next
    End Sub



  #3 (permalink)  
Old March 1st, 2006, 03:33 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Richard,

Wouldn't it be a lot better to disable ViewState on the GridView altogether?

In ASP.NET 1.x, that also meant you lost state for important events (sorting, paging etc), but in .NET 2 this is now stored in control state, separate from ViewSate.

So, I think you're better off setting EnableViewState to False in the control declaration...

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: We've Got A Bigger Problem Now by Dead Kennedys (Track 20 from the album: Plastic Surgery Disasters + In God We Trust) What's This?
  #4 (permalink)  
Old March 1st, 2006, 04:33 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

So you're saying, in ASP.NET 1.x, to do it as below?

<asp:DataGrid ID="grdInventory" AutoGenerateColumns="False" CssClass="inventory" EnableViewState="False" Runat="server">

  #5 (permalink)  
Old March 1st, 2006, 04:38 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

OK. I added EnableViewState="False" and its also working great, posting back immediately. Sweet.

Thanks,
Richard

  #6 (permalink)  
Old March 1st, 2006, 05:21 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Oops. sorry. for some reason I thought you were using .NET 2. I saw grdInventory and thought that was a GridView, but I think it's a DataGrid?

ViewState is used to store information about controls. What this information is, depends on the control. For a DataGrid, you'll see a lot of ViewState being added to the page (look in the HTML source for the __ViewState field). This is because the data for the grid (not the DataSource, but the actual data) is stored in ViewState. That's why you can page or sort without the need to rebind on a post back.

By disabling ViewState on a control, you tell it not to keep its state in ViewState. This is good for performance, because not the entire data is stored in the hidden field. However, you also loose a few benefits:

1. You need to rebind the data on every post back. That is, get the original data from the source or from the cache.

2. The control also looses state about the PageIndex sorting properties.
That means you can't page with a DataGrid without ViewState, unless you deploy your own paging mechanism.

If those aren't problems for you, turning off ViewState is a good thing, as it improves page performance. In fact, I often turn off ViewState on all controls, and only turn it back on when I need it.

In ASP.NET 2 these problems have been minimized. ASP.NET 2 now has ViewState and ControlState. ControlState cannot be turned off, as it is where controls store little bits of information about page index, and other relevant properties.

Does this help?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Urami Bushi by Kill Bill OMPST- Meiko Kaji (Track 15 from the album: Kill Bill (Volume Two)) What's This?
  #7 (permalink)  
Old March 1st, 2006, 05:40 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

That really helps. Yes, grdInventory is a datagrid. Yes, I've seen the montrous __VIEWSTATE on the page.

As fas as the benefits:

1. I don't mind binding the data on every post since I'm using the drop-downs for filters and I figure that every post is more or less going to be unique.

2. Since I'm going to probably have very large pages on this search page with 20,000 to 30,000 row results I was going to deploy custom paging anyway.

And thanks for the tip about turning off the ViewState on controls unless you need it. There is now an incredible difference in performance after making the ViewState False for this datagrid.

Thanks Imar. Much appreciated.

Richard


  #8 (permalink)  
Old March 1st, 2006, 06:03 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

You could even turn in it off for the entire page, through the <@ Page directive.

Just make sure you understand the consequences when you do so (listed earlier), and test thoroughly.... ;)

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
  #9 (permalink)  
Old March 2nd, 2006, 02:03 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Well its good to know all of the different options. So, that's at least three options:

1. For the entire page through the @pagedirective, which turns view state off for everything.
2. On the control itself.
3. Through the Pre_Render function:

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        Dim dgi As DataGridItem
        For Each dgi In grdInventory.Items
            dgi.EnableViewState = False
        Next
    End Sub

Excellent!

  #10 (permalink)  
Old March 2nd, 2006, 05:14 PM
Imar's Avatar
Wrox Author
Points: 72,045, Level: 100
Points: 72,045, Level: 100 Points: 72,045, Level: 100 Points: 72,045, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,083
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Yeah, correct. Each options has its own advantages and disadvantages.

I never used the code method, by setting the EnableViewState through code. I guess it works, but I never had the need to use it...

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic selection of next page based on list box s gurupot JSP Basics 1 December 24th, 2007 06:03 AM
Cross Page Post Back problem akhilesh_g ASP.NET 2.0 Professional 2 December 24th, 2007 04:38 AM
Problem with Cross Page Post Back keaja ASP.NET 2.0 Basics 1 October 31st, 2006 07:00 AM
Post Back Required For Drop Down List alyeng2000 ASP.NET 1.0 and 1.1 Professional 4 March 14th, 2005 01:15 PM
Dynamic Dependent List Box improvement SoC Classic ASP Basics 1 August 16th, 2004 01:02 AM



All times are GMT -4. The time now is 01:29 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.