Connecting Tech Pros Worldwide Help | Site Map

Populate Calender From Content Page Using Master Page in asp.net 2.0

 
LinkBack Thread Tools Search this Thread
  #1  
Old January 11th, 2008, 11:59 AM
Newbie
 
Join Date: Jan 2008
Posts: 1
Default Populate Calender From Content Page Using Master Page in asp.net 2.0

When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm
This breaks this line from working properly
window.opener.document.forms["<%= strFormName %>"]......

How can I fix this and display the date into textbox after selecting the date from Calendar.aspx? This Very Urgent ..........................
If any body help me out

I have given the following Code

******************************
Code For :Master.master
******************************
Expand|Select|Wrap|Line Numbers
  1. <%@ Master Language="VB" CodeFile="Master.master.vb" Inherits="Pages_Master" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" >
  5. <head runat="server">
  6. </head>
  7. <body>
  8. <h1>Standard Header For All Pages</h1>
  9. <asp:ContentPlaceHolder id="CPH1" runat="server">
  10.  
  11. </asp:ContentPlaceHolder>
  12. </body>
  13. </html>
  14.  
**************************************
Code For :PopUpCalendar.aspx
**************************************
This is a Cotent Page
--------------------------------
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" MasterPageFile="Master.master" %>
  2.  
  3. <script runat="server">
  4.  
  5. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  6.  
  7. End Sub
  8. </script>
  9.  
  10. <asp:Content ID="Content1" ContentPlaceHolderId="CPH1" runat="server">
  11. <script type="text/javascript" language="Javascript">    
  12. function GetDate(CtrlName)
  13. {/************ Use Javascript method (window.open) to PopUp a new window 
  14.   which contain a Calendar Control. In the meantime, we'll 
  15.   pass the Parent Form Name and Request Control Name in the QueryString! 
  16.   ******************/
  17.   ChildWindow = window.open('Calendar.aspx?FormName=' + document.forms[0].name + '&CtrlName=' 
  18.                 + CtrlName , "PopUpCalendar", 
  19.                 "width=270,height=270,top=200,left=200,toolbars=no,scrollbars=no,status=no,resizable=no");
  20.  }   
  21.  function CheckWindow()
  22.    {  ChildWindow.close();   }
  23. </script>
  24. <form id="Parent" runat="server">
  25. Start Date:
  26. <asp:TextBox id="txtStartDate" runat="server"></asp:TextBox>
  27. <%-- Pass in the Request Control Name, e.g. txtStartDate, into the Javascript method --%>
  28. <a href="javascript:GetDate('txtStartDate')">Select Date</a>
  29. <br />
  30. End Date:<asp:TextBox id="txtEndDate" runat="server"></asp:TextBox>        
  31. <a href="javascript:GetDate('txtEndDate')">Select Date</a>
  32. </form>
  33. </asp:Content>
  34.  
******************************
Code For :Calendar.aspx
*******************************
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" %>
  2. <script runat="server">
  3.     Public strFormName As String
  4.     Public strCtrlName As String
  5.     Public strSelectedDate As String
  6.  
  7.     Sub Page_Load(Sender As Object, E As EventArgs)
  8.         If Not IsPostBack Then
  9.             '-------------------------------------------------------------------
  10.             ' Set the Calendar to Today's date in the first load
  11.             '-------------------------------------------------------------------
  12.             myCalendar.SelectedDate = System.DateTime.Now()
  13.             '-------------------------------------------------------------------
  14.             ' Set the DropDownList of Month and Year to Current Month and Year
  15.             '-------------------------------------------------------------------
  16.             ddlMonth.Items.FindByValue(DateTime.Now.Month).Selected = True
  17.             ddlYear.SelectedValue = DateTime.Now.Year
  18.             'ddlYear.Items.FindByValue(DateTime.Now.Year).Selected = True
  19.         End If
  20.         '-------------------------------------------------------------------
  21.         ' Set the Selected Date to a temp String
  22.         ' Set FormName and Control Name to 2 String from the values in QueryString
  23.         '-------------------------------------------------------------------
  24.         strSelectedDate = myCalendar.SelectedDate.ToString("dd/MM/yyyy")
  25.         strFormName = Request.QueryString("FormName")
  26.         'strFormName = "Parent"
  27.         strCtrlName = Request.QueryString("CtrlName")
  28.         'strSelectContentId = Request.QueryString("ContentId")
  29.     End Sub
  30.     Sub myCalendar_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
  31.         '-------------------------------------------------------------------
  32.         ' Change the Temp Selected Date Object if change is made
  33.         '-------------------------------------------------------------------
  34.         strSelectedDate = myCalendar.SelectedDate.ToString("dd/MM/yyyy")
  35.     End Sub
  36.     Sub ddl_SelectedIndexChanged(ByVal Sender As Object, ByVal e As EventArgs)
  37.         '-------------------------------------------------------------------
  38.         ' Change the VisibleDate of the Calendar according to 
  39.         ' the DropDownList dynamically
  40.         '-------------------------------------------------------------------
  41.         myCalendar.VisibleDate = New DateTime(CInt(ddlYear.SelectedItem.Value), CInt(ddlMonth.SelectedItem.Value), 1)
  42.     End Sub
  43. </script>
  44. <html xmlns="http://www.w3.org/1999/xhtml" >
  45. <head>
  46.     <script type="text/javascript" language="Javascript">
  47.     function ReturnDate()
  48.         {window.opener.document.forms["<%= strFormName %>"].elements["<%= strCtrlName %>"].value = "<%= strSelectedDate %>";
  49.          window.close();
  50.         }
  51.    function Close()
  52.        {
  53.          window.close();
  54.        }
  55. </script>
  56. </head>
  57. <body>
  58.     <form id="Form1" runat="server">
  59.         <table>
  60.             <tr>
  61.                 <td align="Center">
  62.                     Month:
  63.                     <asp:DropDownList id="ddlMonth" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True">
  64.                         <asp:ListItem Value="1">January</asp:ListItem>
  65.                         <asp:ListItem Value="2">February</asp:ListItem>
  66.                         <asp:ListItem Value="3">March</asp:ListItem>
  67.                         <asp:ListItem Value="4">April</asp:ListItem>
  68.                         <asp:ListItem Value="5">May</asp:ListItem>
  69.                         <asp:ListItem Value="6">June</asp:ListItem>
  70.                         <asp:ListItem Value="7">July</asp:ListItem>
  71.                         <asp:ListItem Value="8">August</asp:ListItem>
  72.                         <asp:ListItem Value="9">September</asp:ListItem>
  73.                         <asp:ListItem Value="10">October</asp:ListItem>
  74.                         <asp:ListItem Value="11">November</asp:ListItem>
  75.                         <asp:ListItem Value="12">December</asp:ListItem>
  76.                     </asp:DropDownList>
  77.                     &nbsp;
  78.                     Year:
  79.                     <asp:DropDownList id="ddlYear" runat="server" OnSelectedIndexChanged="ddl_SelectedIndexChanged" AutoPostBack="True">
  80.                         <asp:ListItem Value="2001">2001</asp:ListItem>
  81.                         <asp:ListItem Value="2002">2002</asp:ListItem>
  82.                         <asp:ListItem Value="2003">2003</asp:ListItem>
  83.                         <asp:ListItem Value="2004">2004</asp:ListItem>
  84.                         <asp:ListItem Value="2005">2005</asp:ListItem>
  85.                         <asp:ListItem>2006</asp:ListItem>
  86.                         <asp:ListItem>2007</asp:ListItem>
  87.                         <asp:ListItem>2008</asp:ListItem>
  88.                         <asp:ListItem>2009</asp:ListItem>
  89.               </asp:DropDownList>
  90.           </td>
  91.             </tr>
  92.             <tr>
  93.                 <td align="Center">
  94.                     <asp:Calendar id="myCalendar" runat="server" BorderWidth="1px" BackColor="#FFFFCC" Width="239px" DayNameFormat="FirstLetter" ForeColor="#663399" Height="200px" Font-Size="8pt" Font-Names="Verdana" BorderColor="#FFCC66" ShowGridLines="True" OnSelectionChanged="myCalendar_SelectionChanged">
  95.                         <SelectorStyle backcolor="#FFCC66"></SelectorStyle>
  96.                         <NextPrevStyle font-size="9pt" forecolor="#FFFFCC"></NextPrevStyle>
  97.                         <DayHeaderStyle height="1px" backcolor="#FFCC66"></DayHeaderStyle>
  98.                         <SelectedDayStyle font-bold="True" backcolor="#CCCCFF"></SelectedDayStyle>
  99.                         <TitleStyle font-size="9pt" font-bold="True" forecolor="#FFFFCC" backcolor="#990000"></TitleStyle>
  100.                         <OtherMonthDayStyle forecolor="#CC9966"></OtherMonthDayStyle>
  101.                     </asp:Calendar>
  102.                 </td>
  103.             </tr>
  104.             <tr>
  105.                 <td align="Center">
  106.                     <input id="btnReturnDate" onclick="javascript:ReturnDate()" type="button" value="Select" runat="Server" />&nbsp; &nbsp;
  107.                     <input id="btnCloseWindow" onclick="javascript:Close()" type="button" value="Close" runat="Server" /></td>
  108.             </tr>
  109.         </table>
  110.     </form>
  111. </body>
  112. </html>

Last edited by Frinavale; January 11th, 2008 at 04:00 PM. Reason: Added [Code] Tags
Reply
  #2  
Old January 11th, 2008, 04:04 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,157
Default

Quote:
Originally Posted by sudip2008
When using the Calendar Popup in a content page of a masterpage the strForName is always set to aspnetForm
This breaks this line from working properly
window.opener.document.forms["<%= strFormName %>"]......

How can I fix this and display the date into textbox after selecting the date from Calendar.aspx? This Very Urgent ..........................
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="VB" %>
  2. <script runat="server">
  3.     Public strFormName As String
  4.     Public strCtrlName As String
  5.     Public strSelectedDate As String
You've declared strFormName, but have not set it to a value.
(Set strFromName = "YourAspFormName")


Aside:
Check this out ...it's a free pop up calendar...and it works very nicely (click on the month, it'll show months in the yaer...then click on the year...it'll show years)

-Frinny
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.