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;
}