dhk3140
asked on
Using a popup calendar control
I have a calendar control in a popup window that worked fine in ASP.NET 1.x; but now that I've upgraded to ASP.NET 2.0/VS 2005 it's quit working. It's supposed to fill in a text box on the original form with the date selected and close, but it just does nothing.
The code in the form that opens the popwindow is:
<a href="javascript:calendar_ window=win dow.open(' calendar.a spx?formna me=Form1.t xtOpenDate ','calenda r_window', 'width=154 ,height=18 8');calend ar_window. focus()">C alendar</a >
This seems to work ok.
The calendar.aspx code is:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="calendar.aspx.vb " Inherits="GamesWanted_AWWC P_calendar " %>
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script runat="server">
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls. DayRenderE ventArgs)
If e.Day.Date = DateTime.Now().ToString("d ") Then
e.Cell.BackColor = System.Drawing.Color.Light Gray
End If
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>Choose a Date</title>
</head>
<body leftmargin="0" topmargin="0">
<form id="Form1" runat="server">
<asp:Calendar id="Calendar1" runat="server" OnSelectionChanged="Calend ar1_Select ionChanged " OnDayRender="Calendar1_day render" showtitle="true" DayNameFormat="FirstTwoLet ters" SelectionMode="Day" BackColor="#ffffff" FirstDayOfWeek="Monday" BorderColor="#000000" ForeColor="#00000" Height="60" Width="125" >
<TitleStyle backcolor="#000080" forecolor="#ffffff" />
<NextPrevStyle backcolor="#000080" forecolor="#ffffff" />
<OtherMonthDayStyle forecolor="#c0c0c0" />
</asp:Calendar>
<asp:Literal id="Literal1" runat="server"></asp:Liter al>
</form>
</body>
</html>
And the codefile is:
Partial Class GamesWanted_AWWCP_calendar
Inherits System.Web.UI.Page
Protected Sub Calendar1_SelectionChanged (ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Dim strjscript As String = "<script language=""javascript"">"
strjscript = strjscript & "window.opener." & HttpContext.Current.Reques t.QueryStr ing("formn ame") & ".value = '" & Calendar1.SelectedDate & "';window.close();"
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
ClientScript.RegisterClien tScriptBlo ck(Me.GetT ype, "returnDate", strjscript)
Literal1.Text = strjscript
End Sub
End Class
Thanks in advance,
Daniel
The code in the form that opens the popwindow is:
<a href="javascript:calendar_
This seems to work ok.
The calendar.aspx code is:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="calendar.aspx.vb
<script language="JavaScript">
<!--
function SymError()
{
return true;
}
window.onerror = SymError;
var SymRealWinOpen = window.open;
function SymWinOpen(url, name, attributes)
{
return (new Object());
}
window.open = SymWinOpen;
//-->
</script>
<script runat="server">
Private Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.
If e.Day.Date = DateTime.Now().ToString("d
e.Cell.BackColor = System.Drawing.Color.Light
End If
End Sub
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<title>Choose a Date</title>
</head>
<body leftmargin="0" topmargin="0">
<form id="Form1" runat="server">
<asp:Calendar id="Calendar1" runat="server" OnSelectionChanged="Calend
<TitleStyle backcolor="#000080" forecolor="#ffffff" />
<NextPrevStyle backcolor="#000080" forecolor="#ffffff" />
<OtherMonthDayStyle forecolor="#c0c0c0" />
</asp:Calendar>
<asp:Literal id="Literal1" runat="server"></asp:Liter
</form>
</body>
</html>
And the codefile is:
Partial Class GamesWanted_AWWCP_calendar
Inherits System.Web.UI.Page
Protected Sub Calendar1_SelectionChanged
Dim strjscript As String = "<script language=""javascript"">"
strjscript = strjscript & "window.opener." & HttpContext.Current.Reques
strjscript = strjscript & "</script" & ">" 'Don't Ask, Tool Bug
ClientScript.RegisterClien
Literal1.Text = strjscript
End Sub
End Class
Thanks in advance,
Daniel
ASKER
Jason:
Here's the textbox code:
<asp:TextBox ID="txtOpenDate" Runat="server" MaxLength="10"></asp:TextB ox>
Form code:
<form id="form1" runat="server">
I don't know if it makes a difference or not, but the form is declared in a master page, and the text box is in a content page. I'm sorta thinking this might be related to the problem, but haven't had a chance to check. I'd really like it to be master/content pages tho.
Thanks,
Daniel
Here's the textbox code:
<asp:TextBox ID="txtOpenDate" Runat="server" MaxLength="10"></asp:TextB
Form code:
<form id="form1" runat="server">
I don't know if it makes a difference or not, but the form is declared in a master page, and the text box is in a content page. I'm sorta thinking this might be related to the problem, but haven't had a chance to check. I'd really like it to be master/content pages tho.
Thanks,
Daniel
dhk3140,
You can do what you want, but what's going to happen when you place your code within the Master Pages scheme with content panes it's going to change the ID of every control that is inside of those panes. This is fine, but you need to be aware of that when you write JavaScript code that tries to reference a specific control.
So what I was hoping you could do was actually load your page in a browser and go to (in IE) the View menu and select Source. So we can see what the new name of the txtOpenDate control is.
It's going to probably be something like:
ctl00_contentHolder_txtOpe nDate
So you'll need to replace your original page's call to the window.open method wtih the appropriate ID.
You can do what you want, but what's going to happen when you place your code within the Master Pages scheme with content panes it's going to change the ID of every control that is inside of those panes. This is fine, but you need to be aware of that when you write JavaScript code that tries to reference a specific control.
So what I was hoping you could do was actually load your page in a browser and go to (in IE) the View menu and select Source. So we can see what the new name of the txtOpenDate control is.
It's going to probably be something like:
ctl00_contentHolder_txtOpe
So you'll need to replace your original page's call to the window.open method wtih the appropriate ID.
ASKER
scolja,
So what you were looking for was:
<input name="ctl00$ContentPlaceHo lder1$txtO penDate" type="text" maxlength="10" id="ctl00_ContentPlaceHold er1_txtOpe nDate" />
And Form1.ctl00_ContentPlaceHo lder1_txtO penDate is what I need to reference instead of Form1.txtOpenDate in the script?
Regards,
Daniel
So what you were looking for was:
<input name="ctl00$ContentPlaceHo
And Form1.ctl00_ContentPlaceHo
Regards,
Daniel
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
scolja,
Actually, the form name changed to aspnetForm. Once I added that, it worked!
Your a genius! Thanks!
Daniel
Actually, the form name changed to aspnetForm. Once I added that, it worked!
Your a genius! Thanks!
Daniel
Just so we're clear, it sounds like the calendar pop-up is opening, but when you select a day on the calendar, nothing appears to happen, including no TextBox being updated and window not closing, right?
If so, this tells me there is probably an issue with this line:
strjscript = strjscript & "window.opener." & HttpContext.Current.Reques
So let's just validate that the TextBox control is truly at Form1.txtOpenDate, by doing a View Source of your original page. Find the txtOpenDate TextBox and make sure that the ID property is set to "txtOpenDate" and that the <form> has an ID of "Form1". If this is all true, we'll probably attempt changing the line I referenced above... but let's see what you come back with.
Good luck!
-- Jason