Help with user control

I have a user control, shown below.  However, due to the javascript, I can have only once instance on a page.   I do not know how to make it reusable, due to the javascript.   I need help.  Thank You.


<%@ Control Language="VB" AutoEventWireup="false" CodeFile="TaborCalendarPopup.ascx.vb" Inherits="Shared_TaborCalendarPopup" %>


<script language="JavaScript" type="text/javascript" src = '../scripts/CalendarPopup.js'> </script>

<script language="JavaScript" type="text/javascript">    var cal1 = new CalendarPopup('divCalendarPopup'); </script>

<div id="divCalendarPopup" style="position:absolute; visibility:hidden; background-color:white;"></div>

<asp:TextBox ID="txtDate" runat="server" clientidmode="static"
                     onkeydown="AllowDate(event);" 
                    width="100px" MaxLength="10"></asp:TextBox>

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="../Images/DateSelector.gif" 
                onclientclick="cal1.select(document.forms[0].txtDate,'txtDate','MM/dd/yyyy'); return false;"/>

<script language="JavaScript" type="text/javascript">

    function AllowDate(evt) {

        var BACKSPACE = 8;
        var FORWARD_SLASH = 191;
        var DELETE = 46;
        var ENDKEY = 35;
        var DOWN_ARROW = 40;
        var ZERO = 48;
        var NINE = 57;
        var NUMPAD0 = 96;
        var NUMPAD9 = 105;
               

        var keyCode = (evt.keyCode ? evt.keyCode : evt.which);

        if (evt.shiftKey) {
            evt.preventDefault();
        }

        else if (!((keyCode == BACKSPACE) ||
                    (keyCode == FORWARD_SLASH) ||
                    (keyCode == DELETE) ||
                    (keyCode >= ENDKEY && keyCode <= DOWN_ARROW) ||
                    (keyCode >= ZERO && keyCode <= NINE) ||
                    (keyCode >= NUMPAD0 && keyCode <= NUMPAD9))) {
            evt.preventDefault();
        }

    }

</script>

Open in new window

LVL 1
HLRosenbergerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jagadishwor DulalSenior Web DeveloperCommented:
Are you talking about AllowDate Function? Create a separate js file and  include it
<script language="JavaScript" type="text/javascript" src = 'filelocation.extension[js]'> </script>

Open in new window

You can call function as you required.
HLRosenbergerAuthor Commented:
Sorry, no not the allow date.  I'm not positive what the issue is, but I mean the fact that I'm using clientidmode="static" on the textbox.  it has to be static because of the onclientclick of the image button; without static it does not work.   However, if I put two of these controls on my page, neither works; It get an error in the CalendarPopup.js code.  I was assuming because ya can't have two elements with an ID of  txtDate.
CodeCruiserCommented:
You will need to replace that static name with a find of some sort. You can use JQuery or plain javascript to traverse the DOM and get the txtDate relative to the current instance of control.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
thanks.  that gave me an idea.  I assigned a unique class runtime for each instance , then find the class in javascript using document.getElementsByClassName(className)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.