Solved

Pop-Up calendar with asp.net, javascript, vb

Posted on 2010-08-30
3
913 Views
Last Modified: 2012-05-10
I'm having a hard time getting this to work.

I have an asp.net page called CreateNewPO with a textbox called txtReqCompDate and a link to a Pop-Up calendar (NewPoCalendar.aspx).

When I click a date on the calendar I want the Pop-Up calendar to close itself and txtReqCompDate to be populated with the date the user picked.

I'm getting this error: "Microsoft JScript runtime error: 'window.opener.document.forms.0.txtReqCompDate' is null or not an object"
CreateNewPO.aspx:



<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage2.master" AutoEventWireup="false" CodeFile="CreateNewPO.aspx.vb" Inherits="Creation_CreateNewPO_CreateNewPO" %>





<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

    <style type="text/css">

        .style7

        {

            width: 80%;

        }

        .style8

        {

            width: 862px;

            font-size: x-large;

        }

        .style9

        {

            width: 168px;

        }

        .style10

        {}

        .style12

        {

            text-align: left;

        }

        .style13

        {

            width: 214px;

            text-align: right;

        }

        .style14

        {

            width: 214px;

            text-align: right;

            height: 28px;

        }

        .style15

        {

            text-align: left;

            height: 28px;

            margin-left: 240px;

        }

    </style>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">

        <asp:Label ID="lblMessage" runat="server" Font-Italic="True" 

            ForeColor="#CC3300"></asp:Label>

    <br />

    <table align="center" class="style7">

        <tr>

            <td class="style8" style="text-align: left">

                Create a New Purchase Order</td>

            <td class="style9">

                <asp:Label ID="lblDate" runat="server" style="font-size: x-large"></asp:Label>

            </td>

        </tr>

    </table>

    <br />

    <table align="center" cellpadding="2" class="style10" 

            style="vertical-align: middle; text-align: center;">

        <tr>

            <td class="style13">

                Vendor</td>

            <td class="style12">

                <asp:Label ID="lblVendor" runat="server" Font-Bold="False" ForeColor="#003300"></asp:Label>

            </td>

        </tr>

        <tr>

            <td class="style13">

                Purchase Order Number</td>

            <td class="style12">

                <asp:TextBox ID="txtPONumber" runat="server" ForeColor="#003300" Width="217px"></asp:TextBox>

            </td>

        </tr>

        <tr>

            <td class="style13">

                Production Month</td>

            <td class="style12">

                <asp:DropDownList ID="drpProductionMonth" runat="server" ForeColor="#003300">

                </asp:DropDownList>

            </td>

        </tr>

        <tr>

            <td class="style13">

                Production Year</td>

            <td class="style12">

                <asp:DropDownList ID="drpProductionYear" runat="server" ForeColor="#003300">

                </asp:DropDownList>

            </td>

        </tr>

        <tr>

            <td class="style13">

                Ship To</td>

            <td class="style12">

                <asp:DropDownList ID="drpShipTo" runat="server" ForeColor="#003300">

                </asp:DropDownList>

            </td>

        </tr>

        <tr>

            <td class="style13">

                Payment Type</td>

            <td class="style12">

                <asp:DropDownList ID="drpPaymentType" runat="server" ForeColor="#003300">

                </asp:DropDownList>

            </td>

        </tr>

        <tr>

            <td class="style14">

                Requested Completion Date</td>

            <td class="style15" valign="middle">

                <asp:TextBox ID="txtReqCompDate" runat="server" ForeColor="#003300" 

                    Width="172px"></asp:TextBox>

&nbsp;                

                <a href="javascript:;" onclick="window.open('NewPOCalendar.aspx?textbox=txtReqCompDate','cal','width=250,height=225,left=270,top=180')">

                <img src="../../img/CalendarIcon.jpg" border="0" alt="Show Calendar" 

                    style="height: 20px; width: 22px" /></a>

            </td>

        </tr>

        <tr>

            <td class="style14">

                &nbsp;</td>

            <td class="style15" valign="middle">

                &nbsp;</td>

        </tr>

    </table>

    <p>

    </p>

</asp:Content>



--------------------------------------------------

NewPoCalendar.aspx:



<%@ Page Language="vb" AutoEventWireup="false" Src="NewPOCalendar.aspx.vb" Inherits="NewPOCalendar1.PopUp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>Calendar</title>

</head>

<body>

<form id="CreateNewPOCalendar" method="post" runat="server">

<asp:Calendar ID="calDate" OnSelectionChanged="Change_Date" Runat="server" />

<input type="hidden" id="control" runat="server" />

</form>

</body>

</html>





--------------------------------------------------

NewPoCalendar.aspx.vb:



Imports System.Web.UI.HtmlControls.HtmlGenericControl



Namespace NewPOCalendar1



    Public Class PopUp

        Inherits System.Web.UI.Page



        Protected WithEvents control As System.Web.UI.HtmlControls.HtmlInputHidden

        Protected WithEvents calDate As System.Web.UI.WebControls.Calendar



        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load

            If Not IsPostBack Then

                control.Value = Request.QueryString("textbox").ToString()

            End If

        End Sub



        Protected Sub Change_Date(sender As System.Object, e As System.EventArgs)

            Dim strScript As String = "<script>window.opener.document.forms[0]." + control.Value + ".value = '"

            strScript += calDate.SelectedDate.ToString("MM/dd/yyyy")

            strScript += "';self.close()"

            strScript += "</" + "script>"

            RegisterClientScriptBlock("anything", strScript)

        End Sub



    End Class



End Namespace

Open in new window

0
Comment
Question by:Rick
  • 2
3 Comments
 
LVL 5

Expert Comment

by:darshan_derasari
Comment Utility
I would like to recommend to use javascript calendar. Please refer below link for that... This achieves same functionality that you want to perorm.

http://www.nsftools.com/tips/DatePickerTest.htm
http://www.javascriptkit.com/script/script2/tengcalendar.shtml

Hope this helps.
0
 
LVL 13

Accepted Solution

by:
Rick earned 0 total points
Comment Utility
0
 
LVL 13

Author Closing Comment

by:Rick
Comment Utility
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now