ajaxRequest in SharePoint

2 posts, 0 answers
  1. Justin Lee
    Justin Lee avatar
    170 posts
    Member since:
    Dec 2009

    Posted 21 Oct 2011 Link to this post

    Is there any known issues with calling RadAjaxManager ajaxRequest from within SharePoint?  Are there any settings/variable I should check in the SharePoint masterpage?

    I have a combobox with AllowCustomText = True.  When the user presses enter, I call ajaxRequest to update a grid on the screen.  The problem is it only works 1 time.  After the first time, ajaxRequest gets called, but the loading panel does not show, and the grid does not update.  I added alerts to make sure that the AjaxManager is found in the javascript, and ajaxRequest calls with no error.  I have set up the same senario in a simple web project, and it works fine.  But when I use it on a page in SharePoint, the issue exists.

    Here is my code:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest" RequestQueueSize="3" />
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Telerik" />
    <telerik:RadComboBox ID="cmbSearch" runat="server" Width="220px" AllowCustomText="True" >
        <ItemTemplate>
            <telerik:RadGrid ID="grdSearch" Width="530px" runat="server" OnNeedDataSource="grdSearch_NeedDataSource">
                ...
            </telerik:RadGrid>
        </ItemTemplate>
        <Items>
            <telerik:RadComboBoxItem runat="server" Text=" "></telerik:RadComboBoxItem>
        </Items>
    </telerik:RadComboBox>


    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid grid = cmbSearch.Items[0].FindControl("grdSearch") as RadGrid;
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadAjaxManager1, grid, RadAjaxLoadingPanel1);
    }

    <telerik:RadCodeBlock ID="rcb1" runat="server">
        <script type="text/javascript">
            window.onload = RegisterSearchEvent;
                 
            function RegisterSearchEvent() {
                var combo = $find("<%= cmbSearch.ClientID %>");
                var input = combo.get_inputDomElement();
                input.attachEvent("onkeydown", searchBoxKeyDown);
             }
     
            function searchBoxKeyDown(e)
            {
                 if (!e)
                     e = window.event;
                 var code = e.keyCode;
                 if (code == 13)
                 {
                     var combo = $find("<%= cmbSearch.ClientID %>");
                     $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest("LoadFilteredData");
                  }
     
                  e.cancelBubble = true;
                  if (e.stopPropagation)
                  {
                      e.stopPropagation();
                  }
                  return false;
              }
          }
      </script>
    </telerik:RadCodeBlock>

    Any help would be appreciated.

    Thanks,
    Justin
  2. Justin Lee
    Justin Lee avatar
    170 posts
    Member since:
    Dec 2009

    Posted 21 Oct 2011 Link to this post

    Sorry, you can ignore, I finally got it fixed.  I'm not sure why this fixed it, but it did. :)

    In the javascript, instead of subscribing to the onload method, I implemented the pageLoad method.  Then I keep track of whether the keydown event is registered or not in a variable. (because pageLoad gets called for each ajax postback)

    var keydownEventRegistered = false;
    function pageLoad() {
        if(!keydownEventRegistered) {
            var combo = $find("<%= cmbSearch.ClientID %>");
            var input = combo.get_inputDomElement();
            input.attachEvent("onkeydown", searchBoxKeyDown);
            keydownEventRegistered = true;
        }
    }

    I don't get why this fixed it, because the way I had it before, the searchBoxKeyDown method WAS getting called each time, and the ajaxRequest was also getting called, it just did nothing.

    Well, at least its working now.

    Thanks,
    Justin

Back to Top