Thursday, February 4, 2010

Displaying the controls of page

Diplaying the controls

Public Sub DisplayControlName(ByVal oControl As Control, ByVal strPageName As String)

Dim txtBox As TextBox
Dim ddlLst As DropDownList
Dim rdBtn As RadioButton
Dim rdBtnLst As RadioButtonList
Dim chkBx As CheckBoxList
Dim chkBx1 As CheckBox
Dim lblVal As System.Web.UI.WebControls.Label
Dim htmTbl As System.Web.UI.HtmlControls.HtmlTable
Dim btnVal As System.Web.UI.WebControls.Button


' Checks for all the WebBased Control in the web page

Select Case oControl.GetType.ToString



'Case "System.Web.UI.WebControls.TextBox" ' for textbox control
' txtBox = oControl.FindControl(oControl.ID)
' If Not txtBox.ID Is Nothing Then
' If Not txtBox.Text.ToString() Is Nothing Then
' If txtBox.Text.Length > 0 Then
' ArrayLst.Add(New String() {strPageName & "_" & txtBox.ID & "_" & "TextBox" & "_" & "N/A", txtBox.Text.ToString()})
' End If
' End If
' End If

Case MultiLang_DropDownListControl ' for Dropdownlist control
ddlLst = oControl.FindControl(oControl.ID)
If Not ddlLst Is Nothing Then

End If

Case MultiLang_RadioButtonControl ' for radio button control
rdBtn = oControl.FindControl(oControl.ID)
If Not rdBtn Is Nothing Then
ArrayLst.Add(New String() {strPageName & "_" & rdBtn.ID & "_" MultiLang_RadioButton & "_" & MultiLang_NA, rdBtn.Text.ToString()})
End If
Case MultiLang_RadioButtonListControl ' for radio button control
rdBtnLst = oControl.FindControl(oControl.ID)
If Not rdBtnLst Is Nothing Then
Dim MyItem As ListItem
For Each MyItem In rdBtnLst.Items
ArrayLst.Add(New String() {strPageName & "_" & rdBtnLst.ID & "_" & MultiLang_RadioButtonList & "_" & MyItem.Value & "_" & MultiLang_NA, MyItem.Text.ToString()})
Next
End If
Case MultiLang_CheckBoxListControl
chkBx = oControl.FindControl(oControl.ID)
If Not chkBx Is Nothing Then
Dim MyItem As ListItem
For Each MyItem In chkBx.Items
ArrayLst.Add(New String() {strPageName & "_" & chkBx.ID & "_" & MultiLang_CheckBoxList &"_" & MyItem.Value & "_" & MultiLang_NA, MyItem.Text.ToString()})
Next
End If
Case MultiLang_CheckBoxControl ' for checkbox control
Try
'Dim strVal As Object
If Not TypeOf oControl.NamingContainer Is CheckBoxList Then
chkBx1 = oControl.FindControl(oControl.ID)
If Not chkBx1 Is Nothing Then
If Not chkBx1.Text.Equals("") Then
ArrayLst.Add(New String() {strPageName & "_" & chkBx1.ID & "_" & MultiLang_CheckBox & "_" & MultiLang_NA, chkBx1.Text.ToString()})
End If
End If
End If
Catch ex As Exception

End Try

Case MultiLang_LabelControl ' for label control
Try
lblVal = oControl.FindControl(oControl.ID)
' HttpContext.Current.Response.Write("
" & "Label:- " & lblVal.Text)
If Not lblVal Is Nothing Then
If Not lblVal.Text.Equals("") Then
ArrayLst.Add(New String() {strPageName & "_" & lblVal.ID & "_" & MultiLang_Label & "_" & MultiLang_NA, lblVal.Text.ToString()})
End If
End If
Catch ex As Exception

End Try


Case MultiLang_HtmlTableControl ' for fetching table control

htmTbl = oControl.FindControl(oControl.ID)
Dim MyRow As System.Web.UI.HtmlControls.HtmlTableRow
Dim mycell As System.Web.UI.HtmlControls.HtmlTableCell
Try
' Travesing each row in the table and then traversing the cells
For Each MyRow In htmTbl.Rows
For Each mycell In MyRow.Cells
If mycell.Controls(0).GetType().ToString().Equals( MultiLang_LiteralControl) Then
' If mycell.InnerText.Length > 0 Then
If Not mycell.ID Is Nothing Then
If Not mycell.InnerText.ToString() Is Nothing Then
If mycell.InnerText.Length > 0 Then
ArrayLst.Add(New String() {strPageName & "_" & mycell.ID & "_" & MultiLang_td & "_" & MultiLang_NA, mycell.InnerText.ToString()})
End If
End If
End If
'End If
End If
Next
Next
Catch ex As Exception

End Try

Case MultiLang_ButtonControl ' for fetching button control
btnVal = oControl.FindControl(oControl.ID)
If Not btnVal Is Nothing Then
ArrayLst.Add(New String() {strPageName & "_" & btnVal.ID & "_" & MultiLang_Button & "_" & MultiLang_NA, btnVal.Text.ToString()})
End If
End Select

No comments:

Post a Comment