M
Mark B
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>
</p>
<table align="center" class="style1" width="950">
<tr>
<td>
Account</td>
</tr>
<tr>
<td>
Navigation Bar</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<h2>
My Account</h2>
</td>
</tr>
<tr>
<td height="0">
<h3>
Settings</h3>
</td>
</tr>
<tr>
<td height="0">
<h4>
</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>
</td>
<td>
Range from:</td>
<td>
</td>
<td>
To:</td>
</tr>
<tr>
<td>
</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>
</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>
</td>
<td>
</td>
<td>
</td>
<td>
</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>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</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
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>
</p>
<table align="center" class="style1" width="950">
<tr>
<td>
Account</td>
</tr>
<tr>
<td>
Navigation Bar</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<h2>
My Account</h2>
</td>
</tr>
<tr>
<td height="0">
<h3>
Settings</h3>
</td>
</tr>
<tr>
<td height="0">
<h4>
</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>
</td>
<td>
Range from:</td>
<td>
</td>
<td>
To:</td>
</tr>
<tr>
<td>
</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>
</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>
</td>
<td>
</td>
<td>
</td>
<td>
</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>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</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