Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

javascript question --auto tabbing using ascx control

Posted on 2004-10-15
7
Medium Priority
?
478 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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 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