View Full Version : PlaceHolder Control
kamlesh_nadar
10-07-03, 06:28 AM
Hi,
I am writing this as I am stuck on a small problem that is –
I am using a Placeholder Control to Add a list of CheckBox dynamically as run time.
Protected WithEvents PH As System.Web.UI.WebControls.PlaceHolder
sql = "Select * from Affiliate_table where user_id = " & strid & ""
objDataReader = objDataAccess.DrGetDRExecuteReader(sql)
While objDataReader.Read
Dim ChkBox As CheckBox = New CheckBox
ChkBox.ID = objDataReader("AffiliateName")
ChkBox.Text = objDataReader("AffiliateName")
PH.Controls.Add(ChkBox)
End While
The above code adds the CheckBox properly, but now later after submitting the page I am not able to read weather the checkbox are left checked or unchecked.
I tried with both but in vain
1. If CType(PH.FindControl(CStr(Arrlst.Item(int))), CheckBox).Checked = True Then
2. For Each ctrl In sender.controls
If ctrl.ID = CStr(Arrlst.Item(int)) Then
Please assist me to find a solution.
Thanking You
Kamliesh Nadar.
The intelligent man is one who has successfully fulfilled many accomplishments, and is yet willing to learn more.
Call - 919821767941.
Hi,
I am writing this as I am stuck on a small problem that is –
I am using a Placeholder Control to Add a list of CheckBox dynamically as run time.
Protected WithEvents PH As System.Web.UI.WebControls.PlaceHolder
sql = "Select * from Affiliate_table where user_id = " & strid & ""
objDataReader = objDataAccess.DrGetDRExecuteReader(sql)
While objDataReader.Read
Dim ChkBox As CheckBox = New CheckBox
ChkBox.ID = objDataReader("AffiliateName")
ChkBox.Text = objDataReader("AffiliateName")
PH.Controls.Add(ChkBox)
End While
The above code adds the CheckBox properly, but now later after submitting the page I am not able to read weather the checkbox are left checked or unchecked.
I tried with both but in vain
1. If CType(PH.FindControl(CStr(Arrlst.Item(int))), CheckBox).Checked = True Then
2. For Each ctrl In sender.controls
If ctrl.ID = CStr(Arrlst.Item(int)) Then
Please assist me to find a solution.
Thanking You
Kamliesh Nadar.
The intelligent man is one who has successfully fulfilled many accomplishments, and is yet willing to learn more.
Call - 919821767941.
Nadar,
Where do you have this code placed? Page_Load?
kamlesh_nadar
10-08-03, 03:02 AM
Hi,
I am loading the ChechBox in Page_Load event and trying to read the values at a Button_click event of a button placed on the page.
Thanking you,
Kamliesh Nadar
msrnivas
10-10-03, 03:22 AM
Hi Kamliesh Nadar
did you got the solution if so pl help me.I am also doing the same this
For j = 0 To indarr.Count - 1
If Trim(rolearr.Item(i)) = Trim(indarr.Item(j)) Then
flag = True
Exit For
End If
Next
objCheckBox = New CheckBox
objCheckBox.Checked = flag
temparr.Add(flag)
objCheckBox.ID = "rolearr" & i
objCheckBox.Text = rolearr.Item(i)
objCheckBox.AutoPostBack = True
plh.Controls.Add(objCheckBox)
flag = False
i can see the all check boxes but when try to get the
checkbox are checked or unchecked in another event (say update) i am gettin the error its saying object is nothing like that.
pl advice me thanks
Hi,
I am loading the ChechBox in Page_Load event and trying to read the values at a Button_click event of a button placed on the page.
Thanking you,
Kamliesh Nadar
You should try loading the CheckBox in the Page_Init event.
madmack
09-22-06, 01:52 PM
I am working on a Client Web Site that allows the user to enter multiple Generic Services. I am using a PlaceHolder (VB.NET). The output is CheckBox, Label and a TextBox if any other user input is necessary. I am demonstrating how to load controls and retrieve the values when user submits.
Loading the Services:
Private plhGenericServices as PlaceHolder
Private Sub LoadGenericServices()
Try
'Load PlaceHolder object with controls used for Generic Services.
plhGenericServices.Controls.Clear()
For Each objGenericServices As genericservice In objJob.Services.GenericServices
Dim objCheck As New CheckBox()
Dim objLabel As New Label()
Dim objText As New TextBox()
Dim ltrLineBreak As LiteralControl = New LiteralControl("<br>")
'Creating control name
Dim strID As String = Replace(objGenericServices.GSName, Space(1), Space(0))
objCheck.ID = "chk" + strID
objLabel.ID = "lbl" + strID
objText.ID = "txt" + strID
'CheckBox
objCheck.Checked = objGenericServices.InitializedFlg
plhGenericServices.Controls.Add(objCheck)
'Label
objLabel.Text = objGenericServices.GSName
plhGenericServices.Controls.Add(objLabel)
'TextBox (If required)
plhGenericServices.Controls.Add(objText)
objText.BorderStyle = BorderStyle.Solid
objText.BorderWidth = 1
'Line Break
plhGenericServices.Controls.Add(ltrLineBreak)
Next
Catch ex As Exception
Throw New Exception("order:LoadGenericServices | Error Client Package Information.", ex)
End Try
End Sub
Retrieving the users selections and input from PlaceHolder:
'Generic Services retrieve
strID = ""
intIndex = 0
For Each objGenericService As genericservice In objJob.Services.GenericServices
For intControl As Integer = intIndex To plhGenericServices.Controls.Count - 1
'Reference CheckBox/TextBox controls only.
If plhGenericServices.Controls(intIndex).GetType() Is GetType(System.Web.UI.WebControls.CheckBox) Then
'If this Service has been selected.
strID = "chk" + Replace(objGenericService.GSName, Space(1), Space(0))
If CType(plhGenericServices.FindControl(strID), CheckBox).Checked Then
'Skip CheckBox and Label to get to TextBox.
intIndex += 2
'Check if the current control is a TextBox.
If plhGenericServices.Controls(intIndex).GetType() Is GetType(System.Web.UI.WebControls.TextBox) Then
'Set Control ID
strID = "txt" + Replace(objGenericService.GSName, Space(1), Space(0))
'TextBox
If CType(plhCustomFields.FindControl(strID), TextBox).Text = String.Empty Then
lstErrorList.Items.Add(GetGlobalResourceObject("Items", "genericservicevalue").ToString() + objGenericService.GSName + _
GetGlobalResourceObject("Items", "isrequired").ToString())
CType(plhGenericServices.FindControl(strID), TextBox).BackColor = objInValidBackColor
Else
CType(plhGenericServices.FindControl(strID), TextBox).BackColor = objValidBackColor
End If
End If
intIndex += 1
Exit For
End If
intIndex += 1
Exit For
End If
intIndex += 1
Next
Next
This is my first attempt at this. It's messey but it does work. Hope this helps.
Naresh Rohra
10-12-06, 08:26 AM
Hi,
The thumb rule is Page.Init should not be used for UI.
Now,
1. If CType(PH.FindControl(CStr(Arrlst.Item(int))), CheckBox).Checked = True Then
Is the ArrLst loaded on the start of the button click (befor this code).
2. For Each ctrl In sender.controls
If ctrl.ID = CStr(Arrlst.Item(int)) Then
I suppose sender control is a "button" so has it any child at all. Even if so again u hav used ArrLst.
Hope this helps,
Naresh Rohra.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.