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

ajaxRequest not working

3 Answers 152 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Geejay
Top achievements
Rank 1
Geejay asked on 02 Jul 2008, 06:46 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 03 Jul 2008, 07:59 AM
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
0
Geejay
Top achievements
Rank 1
answered on 03 Jul 2008, 08:33 AM
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

0
Geejay
Top achievements
Rank 1
answered on 03 Jul 2008, 09:22 AM
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

Tags
Ajax
Asked by
Geejay
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Geejay
Top achievements
Rank 1
Share this question
or