473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help, please: Postback event not firing without ViewState

I have a web app that gets a recordset from the database and fills a
grid. You can drilldown from this table to a detail table.

Because the tables sometimes get huge, and because I have to go back
to the database again every time I postback anyway, I wanted to
disable ViewState in the grids. Just to minimize the amount of stuff
that gets downloaded to the client.

The problem is that none of the postbacks work. They postback, but
when it gets to the end of Page_Load, it just stops and never fires
the event. Both datagrids (the summary and detail) contain
OnSortCommand="DoSort". Sorting is enabled. But the SortCommand
events don't work on either table, and the ItemCommand event doesn't
work on the summary table.

Am I doing something wrong?

Here's the code:

Dim con As OleDbConnection
Private strReportTitle As String = "Player Comping"
Protected SortExpression As String
Protected SortOrder As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con = New OleDbConnection(Application("DSN"))
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'do nifty taskchecker thingie
If Not TFITools.IsTaskAssigned(Me, con.ConnectionString,
"Player Comping") Then
Dim TaskName As String =
TFITools.GetTaskName(con.ConnectionString, "Player Comping")
TaskName = Server.UrlEncode(TaskName)
Response.Redirect("../TaskInvalid.asp?TaskName=" &
TaskName, True)
Exit Sub
End If
'set default sort order
'ViewState("SortOrder") = "Desc"
'Set default from and to dates from bb_revenue table
SetDefaultFromToAuditDates()
End If
AddHandler dgMain.ItemCommand, AddressOf DoDetail
AddHandler dgMain.SortCommand, AddressOf DoSort
AddHandler dgDetail.SortCommand, AddressOf DoSort
End Sub

Private Sub SetDefaultFromToAuditDates()
'Dim cmd As New OleDbCommand("SELECT ISNULL(MIN(AuditDate),
'1/1/1900') 'FromDate', ISNULL(MAX(AuditDate), '1/1/1900') 'ToDate'
from bb_Revenue where Period_ID = 4", con)
'If con.State <> ConnectionState.Open Then con.Open()
'Dim rdr As OleDbDataReader = cmd.ExecuteReader()
'While rdr.Read
' db_FromDate.DefaultDate = CType(rdr("FromDate"),
Date).ToShortDateString
' db_ToDate.DefaultDate = CType(rdr("ToDate"),
Date).ToShortDateString
'End While
'rdr.Close()
'con.Close()
db_FromDate.DefaultDate = Now.ToShortDateString
db_ToDate.DefaultDate = Now.ToShortDateString
End Sub

Private Sub DoMain(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRunReport.Click
'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""

'set title
lblDetailHeader.Text = strReportTitle

'do it
DoReport(dgMain)
End Sub

Private Sub DoDetail(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles dgMain.ItemCommand
If (CType(e.CommandSource, LinkButton)).CommandName = "Detail"
Then
Dim Player_ID As String = e.Item.Cells(0).Text
Dim PlayerName As String =
CType(e.Item.Cells(1).Controls(0), LinkButton).Text

'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""

'set title
lblPlayer_ID.Text = Player_ID
lblDetailHeader.Text = strReportTitle & "<br>Detail for: "
& PlayerName

'do it
DoReport(dgDetail)
End If
End Sub

Private Sub DoReport(ByVal dg As DataGrid)

'set header info
lblReportTime.Text = Now().ToString("MM/dd/yyyy, h:mm tt")
lblUserName.Text = GetUserFullName(Me, Application("DSN"))
lblReportDateRange.Text = db_FromDate.Value & " to " &
db_ToDate.Value

'set Excel Export attributes
IMG1.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", false, false);")
IMG2.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, false);")
IMG3.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, true);")

'set appearances
pnlDetailHeader.Visible = True
pnl_PreReport.Visible = False
pnl_Header.Width = Unit.Percentage(100)
pnl_Header.Visible = True
TFIPanel1.Expanded = False

'do the grid
Dim dt As DataTable
Dim dv As DataView
Dim FromDate As String = db_FromDate.Value
Dim ToDate As String = db_ToDate.Value
Dim Player_ID As String = lblPlayer_ID.Text
Dim RetVal As Int32

'do the specific stuff for this table
If dg.ID = "dgMain" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerComping", New Object(2) {FromDate, ToDate, RetVal})
dgDetail.Visible = False
ElseIf dg.ID = "dgDetail" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerCompingDtl", New Object(3) {FromDate, ToDate, Player_ID,
RetVal})
dgMain.Visible = False
End If

'sort if you need to
dv = dt.DefaultView
If Not Session("SortExpression") = "" Then
dv.Sort = Session("SortExpression") & " " &
ViewState("SortOrder")
End If
dg.DataSource = dv

'bind and display
dg.DataBind()
dg.Visible = True
End Sub

Public Sub DoSort(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dgMain.SortCommand, dgDetail.SortCommand
'change sort direction if the previous column sorted is the
'same as the current column sorted
SortExpression = e.SortExpression
If SortExpression.Equals(Session("SortExpression").To String())
Then
SortOrder =
IIf(Session("SortOrder").ToString().StartsWith("AS C"), "DESC", "ASC")
Else
SortOrder = "ASC"
End If

'set the session variables to new value
Session("SortExpression") = SortExpression
Session("SortOrder") = SortOrder

DoReport(CType(e.CommandSource, DataGrid))
End Sub
Thanks,
Lisa
Nov 18 '05 #1
1 4086
Check out "Enduring an over-sized Viewstate" in this article:

http://msdn.microsoft.com/library/de...idmistakes.asp

It explains your situation and the solution.

--
Hope this helps,
Bryant Hankins
Numinet Systems Inc.
http://www.numinet.com

"Lisa" <li**@starways.net> wrote in message
news:cc**************************@posting.google.c om...
I have a web app that gets a recordset from the database and fills a
grid. You can drilldown from this table to a detail table.

Because the tables sometimes get huge, and because I have to go back
to the database again every time I postback anyway, I wanted to
disable ViewState in the grids. Just to minimize the amount of stuff
that gets downloaded to the client.

The problem is that none of the postbacks work. They postback, but
when it gets to the end of Page_Load, it just stops and never fires
the event. Both datagrids (the summary and detail) contain
OnSortCommand="DoSort". Sorting is enabled. But the SortCommand
events don't work on either table, and the ItemCommand event doesn't
work on the summary table.

Am I doing something wrong?

Here's the code:

Dim con As OleDbConnection
Private strReportTitle As String = "Player Comping"
Protected SortExpression As String
Protected SortOrder As String

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
con = New OleDbConnection(Application("DSN"))
'Put user code to initialize the page here
If Not Page.IsPostBack Then
'do nifty taskchecker thingie
If Not TFITools.IsTaskAssigned(Me, con.ConnectionString,
"Player Comping") Then
Dim TaskName As String =
TFITools.GetTaskName(con.ConnectionString, "Player Comping")
TaskName = Server.UrlEncode(TaskName)
Response.Redirect("../TaskInvalid.asp?TaskName=" &
TaskName, True)
Exit Sub
End If
'set default sort order
'ViewState("SortOrder") = "Desc"
'Set default from and to dates from bb_revenue table
SetDefaultFromToAuditDates()
End If
AddHandler dgMain.ItemCommand, AddressOf DoDetail
AddHandler dgMain.SortCommand, AddressOf DoSort
AddHandler dgDetail.SortCommand, AddressOf DoSort
End Sub

Private Sub SetDefaultFromToAuditDates()
'Dim cmd As New OleDbCommand("SELECT ISNULL(MIN(AuditDate),
'1/1/1900') 'FromDate', ISNULL(MAX(AuditDate), '1/1/1900') 'ToDate'
from bb_Revenue where Period_ID = 4", con)
'If con.State <> ConnectionState.Open Then con.Open()
'Dim rdr As OleDbDataReader = cmd.ExecuteReader()
'While rdr.Read
' db_FromDate.DefaultDate = CType(rdr("FromDate"),
Date).ToShortDateString
' db_ToDate.DefaultDate = CType(rdr("ToDate"),
Date).ToShortDateString
'End While
'rdr.Close()
'con.Close()
db_FromDate.DefaultDate = Now.ToShortDateString
db_ToDate.DefaultDate = Now.ToShortDateString
End Sub

Private Sub DoMain(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnRunReport.Click
'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""

'set title
lblDetailHeader.Text = strReportTitle

'do it
DoReport(dgMain)
End Sub

Private Sub DoDetail(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs) Handles dgMain.ItemCommand
If (CType(e.CommandSource, LinkButton)).CommandName = "Detail"
Then
Dim Player_ID As String = e.Item.Cells(0).Text
Dim PlayerName As String =
CType(e.Item.Cells(1).Controls(0), LinkButton).Text

'reset sorting
Session("SortOrder") = ""
Session("SortExpression") = ""

'set title
lblPlayer_ID.Text = Player_ID
lblDetailHeader.Text = strReportTitle & "<br>Detail for: "
& PlayerName

'do it
DoReport(dgDetail)
End If
End Sub

Private Sub DoReport(ByVal dg As DataGrid)

'set header info
lblReportTime.Text = Now().ToString("MM/dd/yyyy, h:mm tt")
lblUserName.Text = GetUserFullName(Me, Application("DSN"))
lblReportDateRange.Text = db_FromDate.Value & " to " &
db_ToDate.Value

'set Excel Export attributes
IMG1.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", false, false);")
IMG2.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, false);")
IMG3.Attributes.Add("OnClick", "showInExcel(document.all." &
dg.ID.ToString & ", true, true);")

'set appearances
pnlDetailHeader.Visible = True
pnl_PreReport.Visible = False
pnl_Header.Width = Unit.Percentage(100)
pnl_Header.Visible = True
TFIPanel1.Expanded = False

'do the grid
Dim dt As DataTable
Dim dv As DataView
Dim FromDate As String = db_FromDate.Value
Dim ToDate As String = db_ToDate.Value
Dim Player_ID As String = lblPlayer_ID.Text
Dim RetVal As Int32

'do the specific stuff for this table
If dg.ID = "dgMain" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerComping", New Object(2) {FromDate, ToDate, RetVal})
dgDetail.Visible = False
ElseIf dg.ID = "dgDetail" Then
dt = TFITools.GetDataTable(con.ConnectionString,
"p_FRPlayerCompingDtl", New Object(3) {FromDate, ToDate, Player_ID,
RetVal})
dgMain.Visible = False
End If

'sort if you need to
dv = dt.DefaultView
If Not Session("SortExpression") = "" Then
dv.Sort = Session("SortExpression") & " " &
ViewState("SortOrder")
End If
dg.DataSource = dv

'bind and display
dg.DataBind()
dg.Visible = True
End Sub

Public Sub DoSort(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dgMain.SortCommand, dgDetail.SortCommand
'change sort direction if the previous column sorted is the
'same as the current column sorted
SortExpression = e.SortExpression
If SortExpression.Equals(Session("SortExpression").To String())
Then
SortOrder =
IIf(Session("SortOrder").ToString().StartsWith("AS C"), "DESC", "ASC")
Else
SortOrder = "ASC"
End If

'set the session variables to new value
Session("SortExpression") = SortExpression
Session("SortOrder") = SortOrder

DoReport(CType(e.CommandSource, DataGrid))
End Sub
Thanks,
Lisa

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Earl Teigrob | last post by:
I have run into a situation where I need to run the !IsPostBack code under one circumstance, even if it is a postback. Something that may complicate matters more is that this is a double postback...
10
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I...
4
by: BluDog | last post by:
Hi I am trying to test dynamically created controls, to do this i have added a placeholder to a WbForm and added the following code behind: Private Property Count() As Integer Get If...
1
by: seven | last post by:
I'm playing with page inheritence but I am currently stumped by postback, on a page derived from a base class. In my base page/class I have defined an HTMLForm object. It is instantiated and...
2
by: jon | last post by:
I'm trying to establish how to replace a usercontrol that has already been loaded (using LoadControl in the Page.Load event) with a different UserControl following a PostBack. Tying to call...
3
by: Joe | last post by:
Hello All, I am developing a webform which creates ArrayLists of people's names and addresses (the values are retrieved from an xml file) and dynamically drops a user control onto the webform...
0
by: Walter | last post by:
Hi, can someone please help me with my custom control viewstate problem....I haven't slept for hours trying to get this fixed. I am making two custom controls which will be included on a single...
1
by: =?iso-8859-1?B?R2VhcvNpZA==?= | last post by:
Hi, Wierd problem. Using ASP.NET 2.0. Have a DropDownList - <asp:DropDownList ID="DropDownListMake" runat="server" CssClass="selectComparison" AutoPostBack="True"...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.