Solved

javascript question --auto tabbing using ascx control

Posted on 2004-10-15
7
473 Views
Last Modified: 2008-01-09
Hello Expert,

This is bascially a javascript question:

Here is my ASCX user control code in asp.net.

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

<!-- VALADATION JAVASCRIPT IN HELPERFUNCTIONS.JS FILE-->
<script language="JavaScript">
      function KeyUp1(what) {  
        if (what.value.length >= 3)          
            document.all("txtContactPhone_idExchange").focus();    
                  }
                  
            function KeyUp2(what) {  
        if (what.value.length >= 3)          
            document.all("txtContactPhone_idLastFour").focus();    
                  }
                                    
</script>
<asp:textbox id="idAreaCode" title="Enter Phone Area Code Number" runat="server" maxlength="3"
      width="40" onKeyUp="javascript: KeyUp1(this);"></asp:textbox>
<b>-</b>
<asp:textbox id="idExchange" title="Enter Phone Exchange Number" runat="server" maxlength="3"
      width="40" onKeyUp="javascript: KeyUp2(this);"></asp:textbox>
<b>-</b>
<asp:textbox id="idLastFour" title="Enter Phone Last Four Number" Runat="server" MaxLength="4"
      width="45"></asp:textbox>
<asp:Label ID="lblExt" Runat="server" text=" Ext:"></asp:Label><asp:textbox id="idExt" title="Enter Phone Extension Number" Runat="server" MaxLength="5" columns="5"
      width="45"></asp:textbox>

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

I am doing auto tabbing for phone number user control.

i want the javascript to be more generic.

for eg:  document.all("txtContactPhone_idExchange").focus();    

txtcontactphone is the usercontrol name on my asp page.

idexchange is the textbox name on the ascx -usercontrol page

If  i want to use same user control  mutiple times on the same aspx page, i have to provide different names to the control for use.

so basically i cannot hard the usercontrol name here in the ascx control.

can any one help me out.

thanks




0
Comment
Question by:mani_sai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 18

Expert Comment

by:tusharashah
ID: 12321736
txtcontactphone is the usercontrol name on my asp page.

idexchange is the textbox name on the ascx -usercontrol page

(I believe txtcontactphone is TextBox & idexchange is the UserControl)

You can try to Pass ClientID in JavaScript Function from your Code.

txtContactPhone.ClientID will give you actual Client ID of the Control.


-tusahr
0
 
LVL 8

Author Comment

by:mani_sai
ID: 12321782
Thanks for the reply.

If you see the above code:

document.all("txtContactPhone_idExchange").focus();

txtcontactphone is the usercontrol name on my asp page. (not properly named)

idexchange is the textbox name on the ascx -usercontrol page.

txtcontactphone is hard coded on my ascx control page.

i need to pass it generic instead of txtcontactphone(name of the user control) to this code
document.all("txtContactPhone_idExchange").focus();

thanks
0
 
LVL 8

Author Comment

by:mani_sai
ID: 12321829
this is my code on the aspx page:

<%@ Register TagPrefix="PAO4B" TagName="PhoneNumber" Src="controls/USPhoneNo.ascx"%>

<PAO4B:PHONENUMBER id="txtContactPhone" runat="server" required="true"></PAO4B:PHONENUMBER>

so my control name is txtContactPhone.

If i have to use same control on another place on the same page, like this

<PAO4B:PHONENUMBER id="txtWorkPhone" runat="server" required="true"></PAO4B:PHONENUMBER>


then i need to change my javascript user control code to be more generic.

i cannot hard code txtContactPhone
in the code:      document.all("txtContactPhone_idExchange").focus();

please help me out.

thanks


0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
LVL 18

Expert Comment

by:tusharashah
ID: 12321838
Rather then writting in HTML call your function like following from Code Behind

inside your Page_Load add following lines

------------------------------------------------------------------------------------------------
string strExchangeClientID = idExchange.ClientId;
string strLastFourClientID = idLastFour.ClientId;

idAreaCode.Attributes.Add( "OnKeyUp", "KeyUp1(this, '" + strExchangeClientID +"');" );
idLastFor.Attributes.Add( "OnKeyUp", "KeyUp2(this, '" + strLastFourClientID +"');" );

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

-tushar

0
 
LVL 18

Accepted Solution

by:
tusharashah earned 250 total points
ID: 12321848
and your JavaScript function will be something like following:
----------------------------------------------------------------------------------------
<!-- VALADATION JAVASCRIPT IN HELPERFUNCTIONS.JS FILE-->
<script language="JavaScript">
     function KeyUp1(what, vname) {  
        if (what.value.length >= 3)          
            document.all(vname).focus();    
               }
               
          function KeyUp2(what, vname) {  
        if (what.value.length >= 3)          
            document.all(vname).focus();    
               }
                             
</script>
----------------------------------------------------------------------------------------

-tushar
0
 
LVL 8

Author Comment

by:mani_sai
ID: 12322047
Great tushar, it works perfect.

Thanks for your help.
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12322058
Nice to have you going mai_sai!

Thanks for A :)

-tushar
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

630 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