Wrox Programmer Forums
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2007, 04:47 AM
Authorized User
 
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET WebUserControl

Hi ,
can any one help me with this problem please...
I have used Matt Kruse http://www.mattkruse.com javascript to create a popup calender as follows:



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>JavaScript Toolbox - Calendar Popup To Select Date</title>

    <script language="JavaScript" src="javascript/CalendarPopup.js"></script>

    <script language="JavaScript">
    var cal = new CalendarPopup();
    </script>


</head>
<body>
    <form id="form1" runat="server">
        <div class="calendarstyle">
            <input type="text" name="date1" value="" size="15">
            <a href="#" onclick="cal.select(document.forms'form1'].date1,'anchor1','d/MMM/yyyy'); return false;"
                name="anchor1" id="anchor1">Select</a>
      </div>
    </form>
</body>
</html>


it works fine but I need to changed into an asp.net WebuserControl so that i can used in multiple pages.
but it does not work and I get this error message ('cal' is null or not an object) when I click the link to popup the calender.

Regards

Rao


 
Old November 9th, 2007, 03:24 PM
Registered User
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, sorry, but what you have here is a bit confusing. And here is why I feel so. First off does the ASPX PAGE (not a USER CONTROL) work? If not then here's what I'd recommend: Just make it an HTML page and test it from there. My reasoning is that the error you presented is a Javascript error. Also the ASPX PAGE that you show is really only ASPX by the <%@ Page> directive and unless you have some specialized code acting in your CS file there should really be no difference between it's actions and an HTML page.

If the ASPX PAGE you show works, but your efforts to convert it to a USER CONTROL (ASCX file) have failed. Then "we" will need to see what that looks like.

So it sounds like, if "we" are going to help then what "we" really need to see is the ASCX file and/or the JS file.

Glad to help you out but let us know what is going on that way ok?

Thanks and hope this helps you get further along,
Christopher
 
Old November 10th, 2007, 11:08 AM
Authorized User
 
Join Date: Jul 2007
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear rao965,

if you want to have a pop up calender, it is very simple to use the "CalenderExtender" AJAX control. you may visit www.asp.net to view video of this control or if you need any help with the control contact me.


 
Old November 12th, 2007, 11:50 AM
Authorized User
 
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by asmaa
 Dear rao965,

if you want to have a pop up calender, it is very simple to use the "CalenderExtender" AJAX control. you may visit www.asp.net to view video of this control or if you need any help with the control contact me.


Hi asmaa and thanks for your reply,
I agree that " AJAX ExtenderCalendar contrl " is very easy to use but I have been asked to use javascript.


 
Old November 12th, 2007, 12:02 PM
Authorized User
 
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi cdhenderson and thanks for your reply,

Yes the ASPX page works fine, but i wanted to convert it into custom control using the same concept. Here the ASCX file, I am not familiar with javascript so i believe i am calling the javascript incorrectly. I got the javascript from this site (http://www.mattkruse.com/javascript/calendarpopup/)
 and it is too big to add it here.
here is ASCX files

Thanks for you help

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class controls_MyDatePicker : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string clientscript = "javascript:return (cal.select(document.getElementById['txtDate'].txtDate,'anchor1','d/MMM/yyyy'); return false;";
        CalendarImg.Attributes.Add("onclick", clientscript);
    }

    /// <summary>
    /// The text box that the selected date resides in

    /// </summary>
    public TextBox DateTextBox
    {
        get
        {
            return txtDate;
        }
    }
}
-------------------------------------------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyDatePicker.ascx.cs" Inherits="controls_MyDatePicker" %>
 <script language="JavaScript" src="../javascript/CalendarPopup.js"></script>


    <script language="JavaScript">
    var cal = new CalendarPopup();
    </script>

    <div >
        <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
       <a href="../javascript/CalendarPopup.js" onclick="cal.select(document.getElementById['txtDate'].txtDate,'anchor1','MM/dd/yyyy'); return false;"
                name="anchor1" id="anchor1"> <asp:Image ID="CalendarImg" runat=server ImageAlign=AbsMiddle ImageUrl="~/calendar/calendar.gif" /></a>

        </div>












Similar Threads
Thread Thread Starter Forum Replies Last Post
Turning a regular ASP.NET App into an AJAX ASP.Net donrafeal7 Ajax 2 August 31st, 2007 12:33 AM
WebUserControl IsPostBack == true, always elmemo ASP.NET 2.0 Professional 4 May 4th, 2007 05:09 PM
Change style attribute of a WebUserControl YiannisF ASP.NET 1.0 and 1.1 Basics 1 July 10th, 2004 02:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.