472,981 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 software developers and data experts.

Newbie: AJAX not working

This is my first try at using AJAX. I want the calendars to be enabled if
the user checks CheckBox1. It works OK for a normal all page refresh but
once I introduced the AJAX code it stopped working. Any ideas?
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="default-ajax.aspx.vb" Inherits="pages_verify_groups_Default"
Debug="true" %>

<!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>
<style type="text/css">
.style1
{
width: 950px;
}
.style2
{
height: 36px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<p>
&nbsp;</p>
<table align="center" class="style1" width="950">
<tr>
<td>
Account</td>
</tr>
<tr>
<td>
Navigation Bar</td>
</tr>
<tr>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<h2>
My Account</h2>
</td>
</tr>
<tr>
<td height="0">
<h3>
Settings</h3>
</td>
</tr>
<tr>
<td height="0">
<h4>
&nbsp;</h4>
</td>
</tr>
<tr>
<td>
<table>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<tr>
<td colspan="4" class="style2">
<asp:CheckBox ID="CheckBox1" runat="server"
Text=" Activate holiday range" />
</td>
</tr>

<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1"
EventName="CheckedChanged"/>
</Triggers>

<ContentTemplate>
<tr>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</td>
<td>
Range from:</td>
<td>
&nbsp;&nbsp; &nbsp;</td>
<td>
To:</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:Calendar ID="Calendar1" runat="server"
BackColor="White"
BorderColor="Black" BorderStyle="Solid"
CellSpacing="1" Enabled="False"
Font-Names="Verdana" Font-Size="9pt"
ForeColor="Black" Height="250px"
NextPrevFormat="ShortMonth" Width="330px">
<SelectedDayStyle BackColor="#333399"
ForeColor="White" />
<TodayDayStyle BackColor="#999999"
ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True"
Font-Size="8pt" ForeColor="White" />
<DayHeaderStyle Font-Bold="True"
Font-Size="8pt" ForeColor="#333333"
Height="8pt" />
<TitleStyle BackColor="#333399"
BorderStyle="Solid" Font-Bold="True"
Font-Size="12pt" ForeColor="White"
Height="12pt" />
</asp:Calendar>
</td>
<td>
&nbsp;</td>
<td>
<asp:Calendar ID="Calendar2" runat="server"
BackColor="White"
BorderColor="Black" BorderStyle="Solid"
CellSpacing="1" Enabled="False"
Font-Names="Verdana" Font-Size="9pt"
ForeColor="Black" Height="250px"
NextPrevFormat="ShortMonth" Width="330px">
<SelectedDayStyle BackColor="#333399"
ForeColor="White" />
<TodayDayStyle BackColor="#999999"
ForeColor="White" />
<OtherMonthDayStyle ForeColor="#999999" />
<DayStyle BackColor="#CCCCCC" />
<NextPrevStyle Font-Bold="True"
Font-Size="8pt" ForeColor="White" />
<DayHeaderStyle Font-Bold="True"
Font-Size="8pt" ForeColor="#333333"
Height="8pt" />
<TitleStyle BackColor="#333399"
BorderStyle="Solid" Font-Bold="True"
Font-Size="12pt" ForeColor="White"
Height="12pt" />
</asp:Calendar>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td colspan="4">
<asp:CheckBox ID="CheckBox2" runat="server"
Text=" Comments" AutoPostBack="True" />
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style3" colspan="3">
<asp:TextBox ID="TextBox1" runat="server"
Height="181px"
TextMode="MultiLine" Width="686px"
Enabled="False"></asp:TextBox>
</td>
</tr>

</ContentTemplate>
</asp:UpdatePanel>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>
Imports System.Data.SqlClient
Imports System.Data

Partial Class pages_verify_groups_Default
Inherits System.Web.UI.Page
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
fEnableMode()
End Sub

Function fEnableMode() As Boolean

'Enable or disable controls
Select Case CheckBox1.Checked
Case True
Calendar1.Enabled = True
Calendar2.Enabled = True
CheckBox2.Enabled = True
Case Else
Calendar1.Enabled = False
Calendar2.Enabled = False
CheckBox2.Enabled = False
End Select

TextBox1.Enabled = True
If CheckBox2.Enabled = False Or CheckBox2.Checked = False Then
TextBox1.Enabled = False
End If

End Function
Protected Sub CheckBox2_CheckedChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles CheckBox2.CheckedChanged
fEnableMode()
End Sub

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar1.SelectionChanged
fCalendarChange()
End Sub

Function fCalendarChange() As Boolean
Dim strStandardOutOfOfficeText As String
Dim strTo As String
Dim strEnd As String
strStandardOutOfOfficeText = "I am on holiday from "
strTo = " to "
strEnd = "."

Dim strNewOutOfOfficeText As String
'If Left(TextBox1.Text, Len(strStandardOutOfOfficeText)) =
strStandardOutOfOfficeText Or TextBox1.Text = "" Then
strNewOutOfOfficeText = strStandardOutOfOfficeText +
Calendar1.SelectedDate.ToLongDateString + strTo +
Calendar2.SelectedDate.ToLongDateString
TextBox1.Text = strNewOutOfOfficeText + Mid(TextBox1.Text,
Len(strNewOutOfOfficeText)) + strEnd
'End If

End Function

Protected Sub Calendar2_SelectionChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles Calendar2.SelectionChanged
fCalendarChange()
End Sub
End Class



Jun 27 '08 #1
1 1996
Hi Mark,

Based on your description, I've performed some test on my side. It seems
the CheckBox and Calender can work correctly with AJAX page(via
UpdatePanel). here is a very simple test page I've used.

==============aspx====================
<body>
<form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1"
runat="server" />

<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
Checked="true" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1"
EventName="CheckedChanged" />
</Triggers>
<ContentTemplate>

<br />
<br />
<br />
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
<br />
</ContentTemplate>
</asp:UpdatePanel>

<div>
</div>
</form>
</body>
=============code behind================

Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles CheckBox1.CheckedChanged
Calendar1.Enabled = CheckBox1.Checked

End Sub
======================================

I think the problem might be the ASP.NET AJAX application is not configured
correctly. Have you tried some other kind of AJAX postback(via updatepanel)
to see whether it works? Here is the web.config content of my test project,
you can also compare it with yours to see whether any configuration section
is different:

<<<<<<<<<< web.config <<<<<<<<
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions"
type="System.Web.Configuration.SystemWebExtensions SectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting"
type="System.Web.Configuration.ScriptingSectionGro up,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler"
type="System.Web.Configuration.ScriptingScriptReso urceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" requirePermission="false"
allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices"
type="System.Web.Configuration.ScriptingWebService sSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization"
type="System.Web.Configuration.ScriptingJsonSerial izationSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" requirePermission="false"
allowDefinition="Everywhere" />
<section name="profileService"
type="System.Web.Configuration.ScriptingProfileSer viceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" requirePermission="false"
allowDefinition="MachineToApplication" />
<section name="authenticationService"
type="System.Web.Configuration.ScriptingAuthentica tionServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" requirePermission="false"
allowDefinition="MachineToApplication" />
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>

<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="false">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>
</compilation>

<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFact ory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false"
type="System.Web.Script.Services.ScriptHandlerFact ory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<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>

<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>

<system.web.extensions>
<scripting>
<webServices>
<!-- Uncomment this line to customize maxJsonLength and add a custom
converter -->
<!--
<jsonSerialization maxJsonLength="500">
<converters>
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
</converters>
</jsonSerialization>
-->
<!-- Uncomment this line to enable the authentication service.
Include requireSSL="true" if appropriate. -->
<!--
<authenticationService enabled="true" requireSSL = "true|false"/>
-->

<!-- Uncomment these lines to enable the profile service. To allow
profile properties to be retrieved
and modified in ASP.NET AJAX applications, you need to add each
property name to the readAccessProperties and
writeAccessProperties attributes. -->
<!--
<profileService enabled="true"
readAccessProperties="propertyname1,propertyname2"
writeAccessProperties="propertyname1,propertyname2 " />
-->
</webServices>
<!--
<scriptResourceHandler enableCompression="true" enableCaching="true"
/>
-->
</scripting>
</system.web.extensions>

<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode"
type="System.Web.Handlers.ScriptModule, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated" />
<add name="ScriptHandlerFactory" verb="*" path="*.asmx"
preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFact ory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*"
path="*_AppService.axd" preCondition="integratedMode"
type="System.Web.Script.Services.ScriptHandlerFact ory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" preCondition="integratedMode"
verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
</configuration>

<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Mark B" <no**@none.com>
Subject: Newbie: AJAX not working
Date: Tue, 24 Jun 2008 17:12:16 +1200
>
This is my first try at using AJAX. I want the calendars to be enabled if
the user checks CheckBox1. It works OK for a normal all page refresh but
once I introduced the AJAX code it stopped working. Any ideas?
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="default-ajax.aspx.vb" Inherits="pages_verify_groups_Default"
Debug="true" %>

<!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>
<style type="text/css">
.style1
{
width: 950px;
}
.style2
{
height: 36px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<p>
&nbsp;</p>
<table align="center" class="style1" width="950">
<tr>
<td>
Account</td>
</tr>
<tr>
<td>
Navigation Bar</td>
</tr>
<tr>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
<h2>
My Account</h2>
</td>
</tr>
<tr>
<td height="0">
<h3>
Settings</h3>
</td>
</tr>
<tr>
<td height="0">
<h4>
&nbsp;</h4>
</td>
</tr>
<tr>
<td>
<table>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<tr>
<td colspan="4" class="style2">
<asp:CheckBox ID="CheckBox1" runat="server"
Text=" Activate holiday range" />
</td>
</tr>

<asp:UpdatePanel ID="UpdatePanel1"
runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="CheckBox1"
EventName="CheckedChanged"/>
</Triggers>

<ContentTemplate>
<tr>
<td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</td>
<td>
Range from:</td>
<td>
&nbsp;&nbsp; &nbsp;</td>
<td>
To:</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
25
by: meltedown | last post by:
This is supposed ot be an example: http://www.ajaxtutorial.net/index.php/2006/11/30/simple-ajax-using-prototype-part-2/ It says : This example is probably the simplest example you will ever...
1
by: funktiyknow | last post by:
Hello everyone, I am a newbie to javascript and ajax, but have a good background with PHP and XML. I was wondering if anyone could point me to some good resources for learning more about OOP with...
13
by: Karl | last post by:
Hi all. I've recently rebuilt my Vista Ultimate workstation with Visual Studio Team Developer edition. Ive also put on the SQL Server 2005 tools and it's fully patched. I was building a web...
3
by: nuchphasu | last post by:
Hi I have a problem on Dropdownlist that connect database and retrieve data by Ajax.I write javascript like this -------------------------------------------------------------------------...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
1
by: shaunwo | last post by:
I'm an AJAX / DOM Novice (at best) and trying to figure out how to write the value to a couple input fields. I don't remember exactly where I got the ajax.js file I'm using from (went to the website...
9
by: Trapulo | last post by:
Hello, with ASP.NET 2.0 Ajax every unexpected error is managed client-side with a popup that reports the error to the user. In ASP.NET 3.5 this behavor has been changed: how can I have a similar...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.