0

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
2
Contributors
7
Replies
27
Views
7 Months
Discussion Span
Last Post by Link_1
0

I just noticed this warning only shows in IE... it work fine in google chrome.

0

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.

aw this is also i was thinking. Looks like post-redirect-get is the solution but how can I do thjis with what I am trying to do? any ideas?

look like I need to find a javascript which redirect post request to GET request... on page refresh.

Edited by Link_1

1

My first thought is why 2 refreshes? In the first code block with <asp:GridView lines 4 and 6 look like a duplicate. I could be wrong but maybe only one is required?

0

line 4 is view button and line 6 is edit button. i dont see the 2 refreshes? clicking on them will open different vb class

Edited by Link_1

1

Then I'm left with the feeling there's unpublished code here. You shared some of the code but this looks incomplete to me so I have to write as above. Folks have kicked this error around a lot. Read the priors.

0

I am not sure but I have added more of my code. I have look though it for past couple months and still no luck.

SearchAllRecords.aspx.vb

<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/MasterPage.master" CodeFile="SearchAllRecords.aspx.vb" Inherits="UI_SearchAllRecords" %>

<asp:Content id="Home_Content2" ContentPlaceHolderID="ContentPH_main" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="ID" 
    AllowSorting="True"  OnSorting="GridView1_Sorting" AllowPaging="true" PageSize="9" OnPageIndexChanging="GridView1_PageIndexChanging">
        <Columns>
            <asp:TemplateField  runat="server">
                <ItemTemplate>
                    <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>
                            </ItemTemplate>
                    </asp:TemplateField>
                <asp:TemplateField>
                <ItemTemplate>
                    <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>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" Visible="False" />
            'more bound fields
            ... 
    </asp:GridView>
</asp:Content>

'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

    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.SortExpression
        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

        Dim dv As New DataView(dt)
        dv.Sort = sortField.Trim() & " " & ViewState("sortMode")
        GridView1.DataSource = dv
        GridView1.DataBind()
    End Sub

    ' For next page - footer
    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
        GridView1.PageIndex = e.NewPageIndex

        BindGridData()
    End Sub

Edit.aspx.vb

<%@ Page Language="VB" AutoEventWireup="false" MasterPageFile="~/MasterPage.master" CodeFile="Edit.aspx.vb" Inherits="UI_Edit" %>

<asp:Content id="Home_Content2" ContentPlaceHolderID="ContentPH_main" runat="server">
    <asp:TextBox ID="IDNumberTB" class="form-control input-sm" runat="server"></asp:TextBox>
    'more textbox
    ...
    <asp:Button ID="UpdateB" class="btn btn-primary center-block" runat="server" Text="Update Record" />
</asp:Content>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.