Asp.Net GridView Sorting Separate Page
<p>I have an issue with having a asp.net Grid View loaded into a div tag on a page (UI/Host.aspx). The Grid View itself is on a seperate page (GridViews/GridView1.aspx) and I'm using the jQuery load() function to load this page into the div tag. </p>

<p>My problem is when sorting the grid view it tries to postback to the page that's hosting it, and comes back with the error "Unable to find page UI/GridView1.aspx", is there a way to override this so that it post backs to itself, (which I assumed it would but doesn't) or is there an easier way to do the sorting.</p>

<p>Is there any other way of doing this, even if it means getting rid of the GridView altogether and using a repeater and table?</p>

<p>Below is the code:</p>

<p>UI/Hosts.aspx</p>

<p><pre><code>
  //jQuery to load the div with the page UI/Hosts.aspx
  $(document).ready(function() {
    StartRefresh();
  });</p>

<p>function startRefresh()
  {
    refreshID = setInterval(function() {
                DisplayDate();
                $("#divDests").load("../GridViews/Gridview1.aspx?ConfigID=" + $("#ctl00_MainContent_dlConfiguration").val() + "&amp;ModuleID=" + $("#ctl00_MainContent_ddlModule").val());
            }, $("#ctl00_MainContent_ddlRefresh :selected").val());
  }</p>

<p></pre></code></p>

<p>GridViews/Gridview1.aspx;</p>

<pre><code>//Markup for GridViews/Gridview1.aspx
&lt;html&gt;
&lt;head&gt;&lt;title&gt;&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;

&lt;form runat="server"&gt;
    &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;&lt;/asp:ScriptManager&gt;
    &lt;asp:UpdatePanel ID="up1" runat="server"&gt;
        &lt;ContentTemplate&gt;


    &lt;br /&gt;
    &lt;asp:GridView Font-Size="8.7pt" ID="gvLiveDest" runat="server" AutoGenerateColumns="False" 
        EmptyDataText="No Records Found" AllowSorting="true" 
        onsorting="gvLiveDest_Sorting" onrowcreated="gvLiveDest_RowCreated" OnRowDataBound="gvLiveDest_RowDataBound"&gt;
        &lt;Columns&gt;                    
            &lt;asp:TemplateField HeaderText="Name" SortExpression="DestinationName" HeaderStyle-CssClass="centralalignment"&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblDescription" runat="server" Text='&lt;%# WebHelper.HTMLSafe(Eval("Description")) %&gt;' ToolTip='&lt;%# WebHelper.HTMLSafe(Eval("Description")) %&gt;'&gt;&lt;/asp:Label&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:TemplateField HeaderText="Logged &amp;lt;br /&amp;gt; In" HeaderStyle-CssClass="centralalignment" SortExpression="LoggedIn" &gt;
                &lt;ItemStyle CssClass="centralalignment" /&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblLoggedIn" runat="server" Text='&lt;%# SetLoggedIn(Convert.ToBoolean(Eval("Active"))) %&gt;'&gt;&lt;/asp:Label&gt;
                 &lt;/ItemTemplate&gt;
             &lt;/asp:TemplateField&gt;
             &lt;asp:TemplateField HeaderText="Current&amp;lt;br /&amp;gt;Status" HeaderStyle-CssClass="centralalignment" SortExpression="LastStatus" &gt;
                &lt;ItemStyle CssClass="centralalignment" /&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblCurrentStatus" runat="server" Text='&lt;%# WebHelper.HTMLSafe(Eval("LastStatus")) %&gt;' ToolTip='&lt;%#Eval("LastStatus") %&gt;' /&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:TemplateField HeaderText="Time in&amp;lt;br /&amp;gt;Current&amp;lt;br /&amp;gt;Status" HeaderStyle-CssClass="centralalignment" SortExpression="CurrentDuration"&gt;
                &lt;ItemStyle CssClass="RightAlignment" /&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblCurrentTime" runat="server" Text='&lt;%# ICT.DAL.Reporting.CallDurFormat(Eval("CurrentDuration")) %&gt;' /&gt;
                &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
            &lt;asp:BoundField DataField="Lines" HeaderText="Lines" HeaderStyle-CssClass="centralalignment" SortExpression="Lines" 
                ItemStyle-CssClass="centralalignment" /&gt;
            &lt;asp:BoundField DataField="LinesBusy" HeaderText="Lines &amp;lt;br /&amp;gt; Busy" HeaderStyle-CssClass="centralalignment" 
                ItemStyle-CssClass="centralalignment" ReadOnly="True" HtmlEncode="False" SortExpression="LinesBusy" /&gt;
            &lt;asp:BoundField DataField="LinesAvailable" HeaderStyle-CssClass="centralalignment" 
                ItemStyle-CssClass="centralalignment" SortExpression="LinesAvailable" 
                HeaderText="Lines &amp;lt;br /&amp;gt; Available" HtmlEncode="false" ReadOnly="True" /&gt;                            
            &lt;asp:TemplateField HeaderText="Last Call Time" SortExpression="Timestamp" HeaderStyle-CssClass="centralalignment"&gt;
                &lt;ItemTemplate&gt;
                    &lt;asp:Label ID="lblLastCallTime" runat="server" Text='&lt;%# WebHelper.HTMLSafe(Eval("LastCallTime")) %&gt;' ToolTip='&lt;%# WebHelper.HTMLSafe(Eval("LastCallTime")) %&gt;'&gt;&lt;/asp:Label&gt;
                 &lt;/ItemTemplate&gt;
            &lt;/asp:TemplateField&gt;
        &lt;/Columns&gt;
    &lt;/asp:GridView&gt;

            &lt;/ContentTemplate&gt;
    &lt;/asp:UpdatePanel&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>And the onSort Event Code (However it never hits this)</p>

<pre><code>protected void gvLiveDest_Sorting(object sender, GridViewSortEventArgs e)
{
    if (string.Compare(e.SortExpression, ViewState["SortField"].ToString(), true) == 0)
    {
        _sortDir = (_sortDir == "ASC") ? "DESC" : "ASC";
    }
    else
        _sortDir = "ASC";

    _SortField = e.SortExpression;
    ViewState["SortField"] = e.SortExpression;
    ViewState["sortDir"] = _sortDir;

    BindLiveDestination();
}
</code></pre>
