Solved

javascript question --auto tabbing using ascx control

Posted on 2004-10-15
7
459 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 18

Expert Comment

by:tusharashah
Comment Utility
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
Comment Utility
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
Comment Utility
Great tushar, it works perfect.

Thanks for your help.
0
 
LVL 18

Expert Comment

by:tusharashah
Comment Utility
Nice to have you going mai_sai!

Thanks for A :)

-tushar
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

12 Experts available now in Live!

Get 1:1 Help Now