ajaxRequest not working

4 posts, 1 answers
  1. Geejay
    Geejay avatar
    45 posts
    Member since:
    Feb 2007

    Posted 02 Jul 2008 Link to this post

    Hello,

    I'm trying to change some old code to work under ASP.NET Ajax but I'm having difficulties to get it to work. In the 'old' way this was a piece of cake but somewhere I'm missing something. All I want to do in this example is to set the label with a new text, triggered from clientside javascript.
    I've followed many suggestions already in your documentation without result
    The code:

    <%

    @ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    <%
    @ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
    <%
    @ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head runat="server">
    <title>Untitled Page</title>
    </
    head>
    <
    body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>
    <div>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
    function SetLabel()
    {
    var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
    ajaxManager.ajaxRequest(
    "It works");
    }
    </script>
    </telerik:RadCodeBlock>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
    <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
    <UpdatedControls>
    <telerik:AjaxUpdatedControl ControlID="Label1" />
    </UpdatedControls>
    </telerik:AjaxSetting>
    </AjaxSettings>
    </telerik:RadAjaxManager>
    <br />
    <asp:Button ID="Button1" runat="server" OnClientClick="SetLabel()" Text="Button" /><br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </div>
    </form>
    </
    body>
    </
    html>

    Codebehind:

    Partial

    Class _Default
    Inherits System.Web.UI.Page
    Public Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest

    Label1.Text = e.Argument

    End Sub

    Can someone please point me in the right direction?
    Thanks!

    Geert

  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 03 Jul 2008 Link to this post

    Hello Geert,

    You need to set return false after SetLabel() otherwise the button will perform post-back:

    <asp:Button ID="Button1" runat="server" OnClientClick="SetLabel(); return false;" Text="Button" />


    Greetings,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Geejay
    Geejay avatar
    45 posts
    Member since:
    Feb 2007

    Posted 03 Jul 2008 Link to this post

    Hello Vlad,

    Thanks for your reply. I've tried your remark as you describe in http://www.telerik.com/help/aspnet-ajax/ajxclientsideapi.html but no result.
    I do get an 'Sys is not defined' errormessage below the screen when I use OnClientClick="SetLabel(); return false;" which refers to 'Sys.Application.initialize();'
    This may be helpfull?

    greetings Geert

  5. Geejay
    Geejay avatar
    45 posts
    Member since:
    Feb 2007

    Posted 03 Jul 2008 Link to this post

    Hello Vlad,

    I found the answer. It was a missing entry in web.config causing not to load clientside code: 

    <httpHandlers>
    <

    add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
    </httpHandlers>

    greetings Geert

Back to Top