Solved

Help with user control

Posted on 2014-10-06
4
208 Views
Last Modified: 2014-10-06
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

0
Comment
Question by:HLRosenberger
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 40363835
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.
0
 
LVL 1

Author Comment

by:HLRosenberger
ID: 40363850
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.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40363993
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.
0
 
LVL 1

Author Closing Comment

by:HLRosenberger
ID: 40364291
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)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

863 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

19 Experts available now in Live!

Get 1:1 Help Now