Solved

ASP.net Pagejumps when GridView buttons are clicked

Posted on 2013-11-06
4
365 Views
Last Modified: 2013-11-09
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 MaintainScrollPositionOnPostback="true"
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,GridViewRow).RowIndex %>"
                      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,GridViewRow).RowIndex %>"
                      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,GridViewRow).RowIndex %>"
                      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,GridViewRow).RowIndex %>"
                      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,GridViewRow).RowIndex %>"
                      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" />
                <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
                <SortedDescendingCellStyle BackColor="#D6DFDF" />
                <SortedDescendingHeaderStyle BackColor="#002876" />
            </asp:GridView>



 


   Private Sub GridView2_RowCommand1(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView_Questions.RowCommand
        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.CommandArgument)

                ' Retrieve the row that contains the button
                ' from the Rows collection.
                Dim row As GridViewRow = GridView_Questions.Rows(index)

                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.SandyBrown
                End If



            ElseIf (e.CommandName = "MyButton2") Then
                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                ' Retrieve the row that contains the button
                ' from the Rows collection.
                Dim row As GridViewRow = GridView_Questions.Rows(index)

                '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.SandyBrown
                End If

            ElseIf (e.CommandName = "MyButton3") Then
                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                ' Retrieve the row that contains the button
                ' from the Rows collection.
                Dim row As GridViewRow = GridView_Questions.Rows(index)

                '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.SandyBrown
                End If

            ElseIf (e.CommandName = "MyButton4") Then
                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                ' Retrieve the row that contains the button
                ' from the Rows collection.
                Dim row As GridViewRow = GridView_Questions.Rows(index)

                '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.SandyBrown
                End If

            ElseIf (e.CommandName = "MyButton5") Then
                ' Retrieve the row index stored in the CommandArgument property.
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)

                ' Retrieve the row that contains the button
                ' from the Rows collection.
                Dim row As GridViewRow = GridView_Questions.Rows(index)

                '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.SandyBrown
                End If

            End If

        Catch ex As Exception
            Me.Label_Error1.Text = ex.Message
        End Try
    End Sub
0
Comment
Question by:murbro
  • 2
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39627557
What if you through the grid in an update panel?

eg:

<asp:UpdatePanel runat="server" id="UP1">
<contenttemplate>
  <%-- grid goes here %-->
</contenttemplate>
</asp:UpdatePanel>
0
 

Author Comment

by:murbro
ID: 39627595
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.
0
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39627882
add a script manager at the top of the page:

<asp:ScriptManager runat="server" id= "SM1">
</asp:ScriptManager>
0
 

Author Closing Comment

by:murbro
ID: 39635405
Thanks very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now