Creating Multi-Language Custom Control
page 5 of 8
by Abdulla Hussein AbdelHaq
Average Rating: 
Views (Total / Last 10 Days): 35184/ 57

Render Time

Here is the control kitchen, render time. At render time we will add the attributes, render the controls and register startup scripts.

Listing 8

'//English Tab
If ShowEnglish Then
  '<div> English
  writer.AddAttribute("id"Me.ClientID & "_dvEn")
  Select Case ShowLabels
    Case LabelLanguages.Yes
      _lblStatus = "yes"
    Case LabelLanguages.No
      _lblStatus = "no"
  End Select
  Select Case TypeOfControl
    Case ControlToDisplay.TextBox
    Case ControlToDisplay.TextArea
      _txtEnglish.TextMode = TextBoxMode.MultiLine
  End Select
  ' writer.Write("</div")
  writer.RenderEndTag() ' </div>
End If

At first, we are checking if the page developer wants to show the English language in the control. If it assigned to True, then as I mentioned, we have to put the English textbox inside HTML div.

Listing 9

'//English Img
If ShowEnglish Then
  writer.AddStyleAttribute("align", "absmiddle")
  writer.AddStyleAttribute("cursor", "pointer")
  If DefaultLanguage = ControlLanguages.English Then
    If EnglishImageOn = String.Empty Then
      _imgEnglish.ImageUrl = ViewState("Default_En_On")
      _imgEnglish.ImageUrl = EnglishImageOn.Trim
    End If
    If EnglishImageOff = String.Empty Then
      _imgEnglish.ImageUrl = ViewState("Default_En_Off")
      _imgEnglish.ImageUrl = EnglishImageOff.Trim
    End If
  End If
  _imgEnglish.ImageAlign = ImageAlign.AbsMiddle
  writer.AddAttribute("onclick", "ObjJs_" & Me.ID & ".HideShowLang(")
  '//Ajax Enabled
  ScriptManager.RegisterStartupScript(Page, Me.GetType, Me.ID & "_EnBlock", _
  "var " & Me.ClientID & "_collapseEn = new animatedcollapse('" & _
Me.ClientID & "_dvEn', 400, false"IIf(DefaultLanguage = _
  ControlLanguages.English, ",'block'", "") & ");"True)
End If

After rendering the English Textbox, we need to render the English image too, which will be the key for sliding up/sliding down the English Div. As you see in Listing 9, we are registering startup script for the English tab. If the English language is set to be the default language, the ( ‘block’ ) parameter will be passed to the animatedcollapse function to expand the English tab after the page is loaded, otherwise the English div will be collapsed. As you see in Listing 9, we have added an onclick attribute for the English image that will call the JavaScript function “HideShowLang().” Note the name of the JavaScript variable “objJS_”; this is the object instance from JavaScript file “MultiLangJS.js” that will be registered as startup script at render time as seen in Figure 1.

Listing 8 and Listing 9 will be repeated for the left languages.

View Entire Article

User Comments

Title: Good Article   
Name: Vagueraz
Date: 2008-07-04 5:03:31 AM
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
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
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-2024  |  Page Processed at 2024-03-01 4:17:16 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search