I am using VB
Problem: when i click on sort col and click on refresh button, than i get popup browers message "To display the webpage again, the web brower need to resend the infomation you've previously submitted."
Recreate this problem: click on sorting col of gridview -> refresh page
I think its causing this issue bc of two post requests. first post request when I sort on page and 2nd post request when I refresh. I know the issue but I don't know how to fix this.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="ID"
AllowSorting="True" OnSorting="GridView1_Sorting" AllowPaging="true" PageSize="9" OnPageIndexChanging="GridView1_PageIndexChanging">
...
<asp:HyperLink ID="lnkView" runat="server" Visible="true" NavigateUrl='<%# Eval("ID", "View.aspx?ID={0}") %>' OnClick="window.open(this.href,'targetWindow','width=1000,height=1000,scrollbars=1,resizable=1'); return false;">View</asp:HyperLink>
...
<asp:HyperLink ID="lnkEdit" runat="server" Visible="true" NavigateUrl='<%# Eval("ID", "Edit.aspx?ID={0}") %>' OnClick="window.open(this.href,'targetWindow','width=1000,height=1000,scrollbars=1,resizable=1'); return false;">Edit</asp:HyperLink>
...
back end method
'golbal variable
Dim sortField As String
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim da As SqlDataAdapter
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable
Dim sqlConn As New SqlConnection(myConnectionString)
Dim query1 As String = "SELECT * FROM [mytable] ORDER BY Created_dt DESC;"
Try
sqlConn.Open()
Dim cmd = New SqlCommand(query1, sqlConn)
da = New SqlDataAdapter(cmd)
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(da)
da.Fill(ds, "mytable")
Dim a As Integer = ds.Tables("mytable").Rows.Count
If a = 0 Then
ErrorMessage.Text = "0 results found."
End If
da.Fill(dt)
ViewState("SaveData") = dt
GridView1.DataSource = ViewState("SaveData")
GridView1.DataBind()
sqlConn.Close()
Catch ex As Exception
ErrorMessage.Text = "error"
End Try
End If
End Sub
back end method
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
'Retrieve the data source from session state.
Dim dt As DataTable = CType(ViewState("SaveData"), DataTable)
sortField = e.SortExp<b></b>ression
If Trim(ViewState("sortMode")) <> "" Then
If ViewState("sortMode").ToString().Trim().Equals("ASC") Then
ViewState("sortMode") = "DESC"
Else
ViewState("sortMode") = "ASC"
End If
Else
ViewState("sortMode") = "ASC"
End If
'txtSortMode.Text = sortMode
Dim dv As New DataView(dt)
dv.Sort = sortField.Trim() & " " & ViewState("sortMode")
GridView1.DataSource = dv
GridView1.DataBind()
End Sub