Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript question --auto tabbing using ascx control

Posted on 2004-10-15
7
Medium Priority
?
476 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
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 1000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

722 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