Murray Brown
asked on
ASP.net Pagejumps when GridView buttons are clicked
Hi
I have the following GridView on my ASP.net web form. It has five buttons (Event code shown further down) that the user clicks. This usually works fine, but about one in ten users experience a jumpy screen even though I have MaintainScrollPositionOnPo stback="tr ue"
Is there a way to prevent this jumpy screen. Some of the users refuse to use the site because of it.
<asp:GridView ID="GridView_Questions" runat="server" BackColor="White"
BorderColor="#3366CC" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
Height="147px" Visible="False" Width="795px">
<Columns>
<asp:TemplateField HeaderText="Strongly Agree" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="#006600"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button6" runat="server"
CommandName="MyButton1"
CommandArgument="<%# CType(Container,GridViewRo w).RowInde x %>"
Text="Strongly Agree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="#006600" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Agree" HeaderStyle-Font-Size ="Small" ControlStyle-Font-Bold ="false"
ControlStyle-Forecolor ="#009900"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button7" runat="server"
CommandName="MyButton2"
CommandArgument="<%# CType(Container,GridViewRo w).RowInde x %>"
Text="Agree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="#009900" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Undecided" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="SlateGray"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button8" runat="server"
CommandName="MyButton3"
CommandArgument="<%# CType(Container,GridViewRo w).RowInde x %>"
Text="Undecided" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="SlateGray" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Disagree" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="#FF6600"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button9" runat="server"
CommandName="MyButton4"
CommandArgument="<%# CType(Container,GridViewRo w).RowInde x %>"
Text="Disagree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="#FF6600" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Strongly Disagree" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="DarkRed"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button10" runat="server"
CommandName="MyButton5"
CommandArgument="<%# CType(Container,GridViewRo w).RowInde x %>"
Text="Strongly Disagree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="DarkRed" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="White" Font-Bold="False" ForeColor="#000066" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyl e BackColor="#0D4AC4" />
<SortedDescendingCellStyle BackColor="#D6DFDF" />
<SortedDescendingHeaderSty le BackColor="#002876" />
</asp:GridView>
Private Sub GridView2_RowCommand1(send er As Object, e As System.Web.UI.WebControls. GridViewCo mmandEvent Args) Handles GridView_Questions.RowComm and
Try
If Me.Label_LoggedIn.Text = "Not logged in" Then
Me.Label_Error1.Text = "Please log in to complete this survey"
Exit Sub
Else
Me.Label_Error1.Text = ""
End If
If (e.CommandName = "MyButton1") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA rgument)
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in dex)
row.Cells(5).BackColor = Drawing.Color.DarkGreen
row.Cells(6).BackColor = Drawing.Color.DarkGreen
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy Brown
End If
ElseIf (e.CommandName = "MyButton2") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA rgument)
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in dex)
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.Green
row.Cells(6).BackColor = Drawing.Color.Green
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy Brown
End If
ElseIf (e.CommandName = "MyButton3") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA rgument)
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in dex)
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.SlateGray
row.Cells(6).BackColor = Drawing.Color.SlateGray
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy Brown
End If
ElseIf (e.CommandName = "MyButton4") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA rgument)
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in dex)
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.DarkOrange
row.Cells(6).BackColor = Drawing.Color.DarkOrange
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy Brown
End If
ElseIf (e.CommandName = "MyButton5") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA rgument)
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in dex)
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.DarkRed
row.Cells(6).BackColor = Drawing.Color.DarkRed
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy Brown
End If
End If
Catch ex As Exception
Me.Label_Error1.Text = ex.Message
End Try
End Sub
I have the following GridView on my ASP.net web form. It has five buttons (Event code shown further down) that the user clicks. This usually works fine, but about one in ten users experience a jumpy screen even though I have MaintainScrollPositionOnPo
Is there a way to prevent this jumpy screen. Some of the users refuse to use the site because of it.
<asp:GridView ID="GridView_Questions" runat="server" BackColor="White"
BorderColor="#3366CC" BorderStyle="Solid" BorderWidth="1px" CellPadding="4"
Height="147px" Visible="False" Width="795px">
<Columns>
<asp:TemplateField HeaderText="Strongly Agree" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="#006600"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button6" runat="server"
CommandName="MyButton1"
CommandArgument="<%# CType(Container,GridViewRo
Text="Strongly Agree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="#006600" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Agree" HeaderStyle-Font-Size ="Small" ControlStyle-Font-Bold ="false"
ControlStyle-Forecolor ="#009900"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button7" runat="server"
CommandName="MyButton2"
CommandArgument="<%# CType(Container,GridViewRo
Text="Agree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="#009900" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Undecided" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="SlateGray"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button8" runat="server"
CommandName="MyButton3"
CommandArgument="<%# CType(Container,GridViewRo
Text="Undecided" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="SlateGray" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Disagree" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="#FF6600"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button9" runat="server"
CommandName="MyButton4"
CommandArgument="<%# CType(Container,GridViewRo
Text="Disagree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="#FF6600" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Strongly Disagree" HeaderStyle-Font-Size ="Small"
ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="DarkRed"
ControlStyle-Font-Size ="Smaller">
<ItemTemplate>
<asp:Button ID="Button10" runat="server"
CommandName="MyButton5"
CommandArgument="<%# CType(Container,GridViewRo
Text="Strongly Disagree" />
</ItemTemplate>
<ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="DarkRed" />
<HeaderStyle Font-Size="Small" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<HeaderStyle BackColor="White" Font-Bold="False" ForeColor="#000066" />
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
<RowStyle BackColor="White" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SortedAscendingCellStyle BackColor="#EDF6F6" />
<SortedAscendingHeaderStyl
<SortedDescendingCellStyle
<SortedDescendingHeaderSty
</asp:GridView>
Private Sub GridView2_RowCommand1(send
Try
If Me.Label_LoggedIn.Text = "Not logged in" Then
Me.Label_Error1.Text = "Please log in to complete this survey"
Exit Sub
Else
Me.Label_Error1.Text = ""
End If
If (e.CommandName = "MyButton1") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in
row.Cells(5).BackColor = Drawing.Color.DarkGreen
row.Cells(6).BackColor = Drawing.Color.DarkGreen
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy
End If
ElseIf (e.CommandName = "MyButton2") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.Green
row.Cells(6).BackColor = Drawing.Color.Green
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy
End If
ElseIf (e.CommandName = "MyButton3") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.SlateGray
row.Cells(6).BackColor = Drawing.Color.SlateGray
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy
End If
ElseIf (e.CommandName = "MyButton4") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.DarkOrange
row.Cells(6).BackColor = Drawing.Color.DarkOrange
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy
End If
ElseIf (e.CommandName = "MyButton5") Then
' Retrieve the row index stored in the CommandArgument property.
Dim index As Integer = Convert.ToInt32(e.CommandA
' Retrieve the row that contains the button
' from the Rows collection.
Dim row As GridViewRow = GridView_Questions.Rows(in
'row.BackColor = Drawing.Color.LightGray
row.Cells(5).BackColor = Drawing.Color.DarkRed
row.Cells(6).BackColor = Drawing.Color.DarkRed
row.ForeColor = Drawing.Color.White
Dim Q As Integer = CInt(row.Cells(5).Text)
If Q < 6 Then
row.BackColor = Me.G.ForeColor
ElseIf Q > 5 And Q < 11 Then
row.BackColor = Me.R.ForeColor
ElseIf Q > 10 And Q < 16 Then
row.BackColor = Me.E.ForeColor
ElseIf Q > 15 And Q < 21 Then
row.BackColor = Me.A.ForeColor
ElseIf Q > 20 And Q < 26 Then
row.BackColor = Me.T.ForeColor
ElseIf Q > 25 Then
row.BackColor = System.Drawing.Color.Sandy
End If
End If
Catch ex As Exception
Me.Label_Error1.Text = ex.Message
End Try
End Sub
ASKER
I get the error The control with ID 'UP1' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much
eg:
<asp:UpdatePanel runat="server" id="UP1">
<contenttemplate>
<%-- grid goes here %-->
</contenttemplate>
</asp:UpdatePanel>