Calling FireCommand in ScriptManager.Navigate event

2 posts, 0 answers
  1. Simon
    Simon avatar
    25 posts
    Member since:
    Jul 2011

    Posted 31 Aug 2012 Link to this post

    Hey Guys,

    I'm having trouble updating a listview attached to a RadDataPager based on a FireCommand using the result of .NET's History mechanism attached to the scriptmanager.

    I write the history point fine, I retrieve it fine when the user hits "back" - the Navigate event fires and I see the correct index.

    I then try to pass this index to FireCommand on my RadDataPager, but of course the listview and raddatapager, if they do receive the FireCommand, do not update.  Am I missing an AJAx wireup somewhere? I have a RadAjaxManager set up to update the listview and datapager based on the datapager itself but no luck.  I feel like the Navigate event needs to trigger my AjaxManager in some way?

    Any ideas? Thanks.

    Code below:

    <%@ Master Debug="true" Language="C#" MasterPageFile="~/shared/templates/global/AH-Global-L1-2-Column.master" AutoEventWireup="true" CodeFile="listjobs.master.cs" Inherits="global_listjobs" %>
    <%@ Reference Control="~/shared/controls/layout/widgets/JobSearchWidget.ascx" %>
    <%@ Reference Control="~/shared/controls/ddls/CountrySelector.ascx" %>
     
    <asp:Content ID="Content1" ContentPlaceHolderID="cpColumn1" Runat="Server">
        <h1 id="pageTop"><asp:Literal ID="litPageHeading" runat="server" Text="Search Jobs In the Arts" /></h1>
        <div id="searchListSearchWidget">
            <ah:JobSearchWidget ID="JobSearchWidget" runat="server" />
        </div>
        <div id="searchPageSupplementBox">
            <h2>Jobs quick links</h2>
            <ul>
                <li><a href="<%#Config.URLDomain %>jobs/advertise-a-job/" title="Advertise your job on artsHub">Advertise your job on artsHub</a></li>
                <li><a href="<%#Config.URLDomain %>jobs/new-jobs-in-the-last-7-days/" title="View jobs listed in the last 7 days">New jobs in last 7 days</a></li>
                <li><a href="<%#Config.URLDomain %>jobs/new-jobs-in-the-last-14-days/" title="View jobs listed in the last 14 days">New jobs in last 14 days</a></li>
                <li><a href="<%#Config.URLDomain %>jobs/-/-/volunteer/" title="View Volunteer opportunities">View volunteer opportunities</a></li>
                <li><a href="<%#Config.URLDomain %>job-seeker-list.aspx" title="Find the perfect employee on artsHub">Find the perfect employee on artsHub</a></li>
                <li><a href="<%#Config.URLDomain %>my-account/" title="Create a resume and be found!">Create a resume and be found!</a></li>
            </ul>
        </div>
     
        <div class="searchListingMREC"><ah:Banner ID="banSharedMREC" runat="server" ZoneName="V5_MREC_SHARED" /></div>
     
        <ahControls:ListView ID="rlvJobsListPage" runat="server" ItemPlaceholderID="phJobsList" DataSourceId="objJobList" OnItemCreated="rlvJobsListPage_ItemCreated"
             AllowCustomPaging="true" AllowPaging="true" PageSize="20" AllowSorting="True">
            <LayoutTemplate>
                <div id="searchList">
                    <div id="phJobsList" runat="server"></div>
                </div>
            </LayoutTemplate>
            <EmptyDataTemplate>
                No records found
            </EmptyDataTemplate>
            <ItemTemplate></ItemTemplate>            
        </ahControls:ListView>
        <telerik:RadDataPager ID="RadDataPager1" runat="server" PageSize="20" PagedControlID="rlvJobsListPage" OnPageIndexChanged="RadDataPager1_PageIndexChanged">
            <Fields>
                <telerik:RadDataPagerButtonField FieldType="FirstPrev" />
                <telerik:RadDataPagerButtonField FieldType="Numeric" />
                <telerik:RadDataPagerButtonField FieldType="NextLast" />           
            </Fields>
        </telerik:RadDataPager>
        
        <asp:ObjectDataSource ID="objJobList" EnablePaging="True" SelectMethod="SearchJobsList" SelectCountMethod="SearchJobsList_Count" runat="server" TypeName="ArtsHub.BLL.Jobs.Job" OnSelecting="objJobList_Selecting">
            <SelectParameters>
                <asp:Parameter DefaultValue="" Name="searchString" Type="String" ConvertEmptyStringToNull="false" />
                <asp:Parameter Name="publicationId" Type="Int32" DefaultValue="1" />
                <asp:Parameter Name="listingTemplate" Type="int32" DefaultValue="0" />
                <asp:Parameter Name="category" Type="Int32" DefaultValue="0" />
                <asp:Parameter Name="opportunityType" Type="Int32" DefaultValue="0"  />
                <asp:Parameter Name="countryId" Type="Int32" DefaultValue="0" />
                <asp:Parameter Name="regionId" Type="Int32" DefaultValue="0" />
                <asp:Parameter Name="status" Type="Int32" DefaultValue="1" />
                <asp:Parameter Name="searchFuzzinessType" Type="Int32" DefaultValue="0" />
             </SelectParameters>
        </asp:ObjectDataSource>
     
        <telerik:RadAjaxManager ID="ramListJobs" runat="server" DefaultLoadingPanelID="alpListJobs">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadDataPager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rlvJobsListPage" LoadingPanelID="alpListJobs" />
                        <telerik:AjaxUpdatedControl ControlID="RadDataPager1" LoadingPanelID="alpListJobs" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
     
        <telerik:RadAjaxLoadingPanel ID="alpListJobs" runat="server" />
     
     
    </asp:Content>
     
    public partial class global_listjobs : ArtsHub.ArtsHubPage
    {
     
        protected override void OnLoad(EventArgs e)
        {
            ScriptManager.GetCurrent(this.Page).Navigate += new EventHandler<HistoryEventArgs>(CheckAJAXPaging);
     
            //Finally call base class constructor
            base.OnLoad(e);
        }
     
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (HttpContext.Current.Items["newIndex"] != null)
            {
                RadDataPager1.FireCommand("Page", HttpContext.Current.Items["newIndex"].ToString());
                ArtsHub.BLL.Emailing.Emailing.EmailBug("Firing page for newIndex = " + HttpContext.Current.Items["newIndex"].ToString(), "");
            }
            else ArtsHub.BLL.Emailing.Emailing.EmailBug("Context newIndex was null", "");
        }
     
        public void CheckAJAXPaging(object sender, HistoryEventArgs e)
        {
     
            ArtsHub.BLL.Emailing.Emailing.EmailBug("Check AJAX Paging fired - state was " + e.State.Count.ToString(), "");
            if (e.State.Count > 0) ArtsHub.BLL.Emailing.Emailing.EmailBug("Check AJAX Paging fired - key 0 was " + e.State[0].ToString(), "");
     
            if (e.State.Count <= 0)
            {
                // Setup default state
                HttpContext.Current.Items.Add("newIndex", "0");
                //RadDataPager1.FireCommand("Page", "0");
            }
            else
            {
                HttpContext.Current.Items.Add("newIndex", e.State[0].ToString());
     
                //RadDataPager1.FireCommand("Page", e.State[0].ToString());
            }
     
        }
     
        protected void rlvJobsListPage_ItemCreated(object sender, ListViewItemEventArgs e)
        {
            // Grab a reference to the data item
            ListViewDataItem currentItem = (e.Item as ListViewDataItem);
            Job thisListing = (Job)currentItem.DataItem;
     
            // Set the item template to use
            rlvJobsListPage.ItemTemplate = Templating.Render_ITemplate(ArtsHub.Globals.SectionIds.Jobs, thisListing.ListingTemplate, TemplateType.Summary, this);
        }
     
        protected void objJobList_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
        {
            string searchText = (JobSearchWidget.SearchString.Text.Trim().ToLower() == "search text") ? "" : JobSearchWidget.SearchString.Text.Trim();
            e.InputParameters["searchString"] = searchText;
            e.InputParameters["publicationId"] = ArtsHub.Config.PubNum;
            e.InputParameters["category"] = JobSearchWidget.CategorySelector.SelectedCategoryId;
            e.InputParameters["opportunityType"] = JobSearchWidget.OpportunityTypeSelector.SelectedOpportunityType;
            e.InputParameters["countryId"] = JobSearchWidget.CountrySelector.selectedCountryCode;
            e.InputParameters["regionId"] = JobSearchWidget.CountrySelector.selectedRegionId;
            e.InputParameters["searchFuzzinessType"] = JobSearchWidget.SearchAccuracyTypeSelector.SelectedSearchAccuracyType;
        }
     
     
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            rlvJobsListPage.DataBind();
        }
     
        protected void RadDataPager1_PageIndexChanged(object sender, RadDataPagerPageIndexChangeEventArgs e)
        {
           if (Page.IsPostBack) ScriptManager.GetCurrent(this.Page).AddHistoryPoint("p", e.NewPageIndex.ToString(), "Job Search Page " + e.NewPageIndex.ToString());
        }
     
    }
  2. Simon
    Simon avatar
    25 posts
    Member since:
    Jul 2011

    Posted 03 Sep 2012 Link to this post

    Solved.
    I did indeed have to AJAX up the script manager to the pager and listview.
    As the script manager is in a nested root master page, I had to call the GetCurrent() method to get a reference to it.
    Therefore, the AJAX link up had to be done programatically.

    Works great now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top