Creating Multi-Language Custom Control
page 7 of 8
by Abdulla Hussein AbdelHaq
Feedback
Average Rating: 
Views (Total / Last 10 Days): 39569/ 182

Tips and Tricks

You may ask what if I want to do some thing with the Textbox that is not supported as a property, like settings the English Textbox as a Default focus. Fortunately, if you look at listing 11, there is a read-only property that gives me the ID for the English Textbox, so you can search about the Textbox on the page using that property and you can add more styles and more attributes to the Textbox.

Note the Browsable(False) attribute placed above the property, it means that the property will not appear in the properties window or in the html design time, you can access it from code behind only.

Listing 11

< _
    Category("Misc"), _
    Browsable(False), _
    Description("ID of English TextBox.") _
    > _
    Public ReadOnly Property EnglishTextBoxID() As String
  Get
  EnsureChildControls()
  Return _txtEnglish.ID
  End Get
End Property

As you can see in Listing 12, I set the English Textbox as Default Focus. You can reform the Textbox as you want; I have changed the back color for the Arabic Textbox into Blue.

Listing 12

'//Set English Textbox as DefaultFocus
Page.Form.DefaultFocus = _
MultiLang1.FindControl(MultiLang1.EnglishTextBoxID).ClientID
DirectCast(MultiLang1.FindControl(MultiLang1.ArabicTextBoxID), TextBox).BackColor = _
Drawing.Color.Blue

What about client-side validation.  Suppose that the French Textbox was a required field. In that case, we have to write a JavaScript function, and call it in the button event OnClientClick.

If you back again to the downloaded source code, open the JavaScript file “MultiLangJS.js”; you will see a lot of JavaScript variables that be assigned to the passed arguments.

 One of these variables is “this.imgFrId.”   It is the ClientID for the French Image and we have passed it via the script block during render time.

Also, we have the JavaScript variable “this.txtFrObj.” It is the object from the French Textbox. As you can see in listing 13, we are passing the ClientID for the French Image to the “HideShowLang()” function, which is the responsible for sliding the contents.

The “HideShowLang()” function receive the Image ClientID for the content you want to Slide it down. So, for sliding down the French div, we should pass the ClientID for the French Image, so the French div will slide down and the other languages div’s will slide up.

Listing 13

//JavaScript Funciton
function PageValidation()
  {
   if(ObjJs_MultiLang1.txtFrObj.value =='')
   {
     alert('Please Enter Text in French');
     ObjJs_MultiLang1.HideShowLang(ObjJs_MultiLang1.imgFrId);
     ObjJs_MultiLang1.txtFrObj.focus();
     return false;
   }
   return true;
 }

View Entire Article

User Comments

Title: Good Article   
Name: Vagueraz
Date: 2008-07-04 5:03:31 AM
Comment:
Very Good and Strong Article , and it's not only useful for devlopers also for end-users ....
Title: Outstanding Work   
Name: Jean-Pierre Jamous
Date: 2008-07-02 10:01:11 PM
Comment:
Extremely nice. It comes handy for developers. You've done a tremendous job at it. Keep up the great work.
Title: Very good article   
Name: Anas al-qudah
Date: 2008-07-02 4:03:52 AM
Comment:
It's realy Very good article and help me.
Thanks thanks alot.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-05-26 7:25:14 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search