Solved

javascript question --auto tabbing using ascx control

Posted on 2004-10-15
7
470 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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