2 Replies - 493 Views - Last Post: 10 July 2017 - 09:52 AM Rate Topic: -----

#1 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 178
  • Joined: 20-May 16

to display the webpage again, the web browser needs to resend the info

Posted 10 July 2017 - 07:46 AM

I am using VB

I have a gridview. User should be able to sort by clicking on col name in gridview.

Error: to display the webpage again, the web browser needs to resend the information you'vs previously submitted. If you were making a purchase, you should click Cancel to avoid a duplicate transcation. Otherwise click retry to display the webpage again.

I understand this error is showing up bc of double post request. But I am not sure how to fix it.

I am looking at code example from microsoft website

https://msdn.microso...(v=vs.110).aspx

	
	
	
	<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
	... 
	AllowSorting="True"  OnSorting="GridView1_Sorting" 
	... >
		...
	</asp:GridView>



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            BindGridData()
        End If
    End Sub


    Protected Sub BindGridData()
        Dim da As SqlDataAdapter
        Dim ds As DataSet = New DataSet()
        Dim dt As DataTable = New DataTable
        Dim sqlConn As New SqlConnection(myConnectionString)

        Try
            sqlConn.Open()

            Dim Query1 As String = "SELECT * FROM [tbl] ORDER BY CurrentDate DESC;"
            Dim cmd = New SqlCommand(Query1, sqlConn)

            da = New SqlDataAdapter(cmd)
            Dim builder As SqlCommandBuilder = New SqlCommandBuilder(da)
            da.Fill(ds, "tbl_ChangeManagementFrm")
         
            da.Fill(dt)
            ViewState("SaveData") = dt
            GridView1.DataSource = ViewState("SaveData")
            GridView1.DataBind()

            sqlConn.Close()
        Catch ex As Exception
            ...
        End Try
    End Sub




	Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
        'Retrieve the table from the session object.
        Dim dt = TryCast(ViewState("SaveData"), DataTable)
        If dt IsNot Nothing Then
            'Sort the data.
            dt.DefaultView.Sort = e.SortExpression & " " & GetSortDirection(e.SortExpression)
            GridView1.DataSource = ViewState("SaveData")
            GridView1.DataBind()
        End If
    End Sub




    
Private Function GetSortDirection(ByVal column As String) As String
        ' By default, set the sort direction to ascending.
        Dim sortDirection = "ASC"
        ' Retrieve the last column that was sorted.
        Dim sortExpression = TryCast(ViewState("SortExpression"), String)
        If sortExpression IsNot Nothing Then
            ' Check if the same column is being sorted.
            ' Otherwise, the default value can be returned.
            If sortExpression = column Then
                Dim lastDirection = TryCast(ViewState("SortDirection"), String)
                If lastDirection IsNot Nothing _
                  AndAlso lastDirection = "ASC" Then
                    sortDirection = "DESC"
                End If
            End If
        End If
        ' Save new values in ViewState.
        ViewState("SortDirection") = sortDirection
        ViewState("SortExpression") = column
        Return sortDirection
    End Function

This post has been edited by ikhlas06: 10 July 2017 - 07:49 AM


Is This A Good Question/Topic? 0
  • +

Replies To: to display the webpage again, the web browser needs to resend the info

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 5074
  • View blog
  • Posts: 13,697
  • Joined: 18-April 07

Re: to display the webpage again, the web browser needs to resend the info

Posted 10 July 2017 - 08:47 AM

Are you doing something before clicking the column that would cause something to change? Like did you delete or create a record and then after it creates it you click the column sort? Usually these types of errors are because you did something that is going to change information and it is preventing you from changing the data again accidentally.

From what you have shown I don't see anything that would cause such an error to appear unless you actually did something prior to the sorting. One thing you can try is to just reload the page fresh (like going into the URL and just hitting enter) and then try to sort.
Was This Post Helpful? 1
  • +
  • -

#3 ikhlas06  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 178
  • Joined: 20-May 16

Re: to display the webpage again, the web browser needs to resend the info

Posted 10 July 2017 - 09:52 AM

i did tried to refresh the page but it doesn't run rest of code



    Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)

        Response.Redirect(Request.Url.AbsoluteUri)

        'Retrieve the table from the session object.
        Dim dt = TryCast(ViewState("SaveData"), DataTable)

        If dt IsNot Nothing Then
            'Sort the data.
            dt.DefaultView.Sort = e.SortExpression & " " & GetSortDirection(e.SortExpression)
            ViewState("SaveSort") = dt.DefaultView.Sort
            GridView1.DataSource = ViewState("SaveSort")
            GridView1.DataSource = ViewState("SaveData")
            GridView1.DataBind()
        End If

    ' Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

This post has been edited by ikhlas06: 10 July 2017 - 09:54 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1