This is a migrated thread and some comments may be shown as answers.

ajaxRequest in SharePoint

1 Answer 71 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Justin Lee
Top achievements
Rank 1
Justin Lee asked on 21 Oct 2011, 02:43 PM
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

1 Answer, 1 is accepted

Sort by
0
Justin Lee
Top achievements
Rank 1
answered on 21 Oct 2011, 03:31 PM
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

Tags
Ajax
Asked by
Justin Lee
Top achievements
Rank 1
Answers by
Justin Lee
Top achievements
Rank 1
Share this question
or