Click here to Skip to main content
15,898,374 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionConnection error Pin
zenithmaximus5-Jun-06 18:20
zenithmaximus5-Jun-06 18:20 
QuestionFind maximum value from a record Pin
mayhem_rules5-Jun-06 18:07
mayhem_rules5-Jun-06 18:07 
AnswerRe: Find maximum value from a record Pin
Kschuler6-Jun-06 10:49
Kschuler6-Jun-06 10:49 
GeneralRe: Find maximum value from a record Pin
mayhem_rules6-Jun-06 20:47
mayhem_rules6-Jun-06 20:47 
GeneralRe: Find maximum value from a record Pin
Kschuler7-Jun-06 2:52
Kschuler7-Jun-06 2:52 
QuestionWindow Service Pin
nitin_ion5-Jun-06 17:42
nitin_ion5-Jun-06 17:42 
QuestionHow To Set a User Control Property from a VB Code Module? [modified] Pin
hmaccord5-Jun-06 16:24
hmaccord5-Jun-06 16:24 
AnswerRe: How To Set a User Control Property from a VB Code Module? [modified] Pin
hmaccord9-Jun-06 1:24
hmaccord9-Jun-06 1:24 
I found the answer I needed ... after much trial and error. I also realized that this message might be more appropriately posted into the ASP.NET discussion ... but too late once posted. Here was my solution which I current have working (using VB code ... but also applies to C# ... just some different coding techniques):

(1) I defined a parent class object for each of my control classes. Initially I am working primarily with my user controls ... but the same process applies to other control classes. In the parent class I inherit the control class object. Then I defined an overridable "dummy" method and properties that I want to be consistent in all of my controls.
(2) In the controls involved I inherit the parent class that I created. I also define Overrides properties and methods to match the parents.
(3) I also wrote a class that can be invoked from the page script that loops thru the entire control collection (including all of the roots) for the page to find the specific control that I am looking for. Once found, I do a CType of the parent for the control so it is of the correct type. At this point I can directly invoke the overridable method and set the properties ... which actually are the derived methods and properties of the specific control. This approach allows me to avoid using the Reflect class which in itself adds a lot of overhead on the server execution. This approach allows me to invoke a control's method or set its properties from the LOAD event of the page, before the LOAD event of the control is triggered.

Harry

Here is the code for the class that does the search and invoke:

Imports Microsoft.VisualBasic

Public Class clsIPUBFW_Utils

Private strModID As String = "clsIPUBFW_Utils"

Public Sub PostControlState(ByRef pgObj As Page, ByVal strControlsWithState As String)
Dim strProcID As String = "PostControlState"
On Error GoTo ModErrHandler
' This procedure is invoked during the start of the Page LOAD event
' determines if any controls have indicated during their INIT that they maintain state
' and if so, this procedure checks for the control and then invokes the method of the control
' that updates the controls properties from state at the start of the Page's LOAD event

' strControlsWithState is a string that has bar delimited values. The values are added by
' the control's in their INIT event if they use a state model (PGVIEW or SESSION). The format of the
' value is: statemodel - controltype - pageid { parentid : controlid }

If strControlsWithState <> "" Then
Dim objControlsWithState As Object = Split(strControlsWithState, "|")
Dim intLoop As Integer
Dim strCntlName As String
Dim strCntlType As String

For intLoop = 0 To UBound(objControlsWithState)
strCntlName = fIPUBFW_strControlName(objControlsWithState(intLoop))
strCntlType = fIPUBFW_strControlType(objControlsWithState(intLoop))
Call FindAndInvoke(pgObj, strCntlName, strCntlType)
Next
End If

Exit Sub
ModErrHandler:
Call pIPUBFW_ModuleErrorHandler(Err.Description, Err.Number, strModID, strProcID)
End Sub
Private Sub FindAndInvoke(ByRef pgObj As Page, ByVal strCntlName As String, ByVal strCntlType As String)
Dim strProcID As String = "FindAndInvoke"
On Error GoTo ModErrHandler

Select Case UCase(strCntlType)
Case "USER"
Dim cntlToSet As clsIPUBFW_UserCntl
cntlToSet = CType(GetControl(pgObj, strCntlName), clsIPUBFW_UserCntl)
' clsIPUBFW_UserCntl is the class name of the Parent control class for my User controls
cntlToSet.pPostControlStatesToProperties()


' *** AS MORE CONTROL TYPES ARE ADDED THEY CAN BE DEFINED HERE ***


End Select

Exit Sub
ModErrHandler:
Call pIPUBFW_ModuleErrorHandler(Err.Description, Err.Number, strModID, strProcID)
End Sub
Private Function GetControl(ByRef pgObj As Page, ByVal strCntlName As String) As Control
Dim strProcID As String = "GetControl"
On Error GoTo ModErrHandler
' this routine loops thru the control collection (up to 10 tiers of the family tree) to locate
' the desired control that is assumed to be present in the collection

Dim i1, i2, i3, i4, i5, i6, i7, i8, i9, i10 As Integer
Dim cntlWrk1, cntlWrk2, cntlWrk3, cntlWrk4, cntlWrk5, cntlWrk6, cntlWrk7, cntlWrk8, cntlWrk9, cntlWrk10 As Control
Dim strParentID As String = ""
Dim strControlID As String = ""
Dim intPrt As Integer = InStr(strCntlName, ":")
strParentID = Left(strCntlName, (intPrt - 1))
strControlID = Right(strCntlName, (Len(strCntlName) - intPrt))

GetControl = Nothing

If pgObj.HasControls Then
For i1 = 0 To pgObj.Controls.Count - 1
cntlWrk1 = pgObj.Controls(i1)
If PageControlFound(cntlWrk1, strParentID, strControlID) Then
GetControl = cntlWrk1
Exit Function
End If
If cntlWrk1.HasControls Then
For i2 = 0 To cntlWrk1.Controls.Count - 1
cntlWrk2 = cntlWrk1.Controls(i2)
If PageControlFound(cntlWrk2, strParentID, strControlID) Then
GetControl = cntlWrk2
Exit Function
End If
If cntlWrk2.HasControls Then
For i3 = 0 To cntlWrk2.Controls.Count - 1
cntlWrk3 = cntlWrk2.Controls(i3)
If PageControlFound(cntlWrk3, strParentID, strControlID) Then
GetControl = cntlWrk3
Exit Function
End If
If cntlWrk3.HasControls Then
For i4 = 0 To cntlWrk3.Controls.Count - 1
cntlWrk4 = cntlWrk3.Controls(i4)
If PageControlFound(cntlWrk4, strParentID, strControlID) Then
GetControl = cntlWrk4
Exit Function
End If
If cntlWrk4.HasControls Then
For i5 = 0 To cntlWrk4.Controls.Count - 1
cntlWrk5 = cntlWrk4.Controls(i4)
If PageControlFound(cntlWrk5, strParentID, strControlID) Then
GetControl = cntlWrk5
Exit Function
End If
If cntlWrk5.HasControls Then
For i6 = 0 To cntlWrk5.Controls.Count - 1
cntlWrk6 = cntlWrk5.Controls(i6)
If PageControlFound(cntlWrk6, strParentID, strControlID) Then
GetControl = cntlWrk6
Exit Function
End If
If cntlWrk6.HasControls Then
For i7 = 0 To cntlWrk6.Controls.Count - 1
cntlWrk7 = cntlWrk6.Controls(i7)
If PageControlFound(cntlWrk7, strParentID, strControlID) Then
GetControl = cntlWrk7
Exit Function
End If
If cntlWrk7.HasControls Then
For i8 = 0 To cntlWrk7.Controls.Count - 1
cntlWrk8 = cntlWrk7.Controls(i8)
If PageControlFound(cntlWrk8, strParentID, strControlID) Then
GetControl = cntlWrk8
Exit Function
End If
If cntlWrk8.HasControls Then
For i9 = 0 To cntlWrk8.Controls.Count - 1
cntlWrk9 = cntlWrk8.Controls(i9)
If PageControlFound(cntlWrk9, strParentID, strControlID) Then
GetControl = cntlWrk9
Exit Function
End If
If cntlWrk9.HasControls Then
For i10 = 0 To cntlWrk9.Controls.Count - 1
cntlWrk10 = cntlWrk9.Controls(i10)
If PageControlFound(cntlWrk10, strParentID, strControlID) Then
GetControl = cntlWrk10
Exit Function
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If

Exit Function
ModErrHandler:
Call pIPUBFW_ModuleErrorHandler(Err.Description, Err.Number, strModID, strProcID)
End Function
Private Function PageControlFound(ByRef cntlObj As Control, ByVal strParentID As String, ByVal strCntlID As String) As Boolean
Dim strProcID As String = "PageControlFound"
On Error GoTo ModErrHandler
' this routine checks for an ID match on the parentID and controlID within the page control collection

Dim strColCntlID As String = ""
Dim strColParentID As String = ""
Dim blnOut As Boolean = False

If Not cntlObj Is Nothing Then
strColCntlID = cntlObj.ID
strColParentID = cntlObj.Parent.ID
' check for ID match ... if so execute the control`s post state method
If UCase(strColParentID) = UCase(strParentID) And UCase(strColCntlID) = UCase(strCntlID) Then
blnOut = True
End If
End If
PageControlFound = blnOut

Exit Function
ModErrHandler:
Call pIPUBFW_ModuleErrorHandler(Err.Description, Err.Number, strModID, strProcID)
End Function

End Class
QuestionAbout ADODB connection!!! Pin
orananif5-Jun-06 14:58
orananif5-Jun-06 14:58 
QuestionData Passing Pin
New_Coder5-Jun-06 12:00
New_Coder5-Jun-06 12:00 
QuestionCheck security for editing of datagrid Pin
Sai_Ram5-Jun-06 11:02
Sai_Ram5-Jun-06 11:02 
AnswerRe: Check security for editing of datagrid Pin
Syed Ali Raza5-Jun-06 12:24
Syed Ali Raza5-Jun-06 12:24 
QuestionCapturing an image through webcam in VB6.0 Pin
gsaichaitanya5-Jun-06 5:27
gsaichaitanya5-Jun-06 5:27 
QuestionVB.NET - XtraReport Not responding Pin
obuli_salem5-Jun-06 4:36
obuli_salem5-Jun-06 4:36 
QuestionProblem using textbox for searching in DataGrid Pin
Syed Ali Raza5-Jun-06 4:14
Syed Ali Raza5-Jun-06 4:14 
AnswerRe: Problem using textbox for searching in DataGrid Pin
Kschuler5-Jun-06 8:46
Kschuler5-Jun-06 8:46 
GeneralRe:Thanks Pin
Syed Ali Raza5-Jun-06 12:00
Syed Ali Raza5-Jun-06 12:00 
Questionprogress bar Pin
militiaware5-Jun-06 4:09
militiaware5-Jun-06 4:09 
Questionidle system Pin
militiaware5-Jun-06 3:43
militiaware5-Jun-06 3:43 
Questionstream reader Pin
militiaware5-Jun-06 3:27
militiaware5-Jun-06 3:27 
AnswerRe: stream reader Pin
Dustin Metzgar5-Jun-06 4:02
Dustin Metzgar5-Jun-06 4:02 
QuestionMSHflexgrid and images question Pin
Tarek Jabri5-Jun-06 3:01
Tarek Jabri5-Jun-06 3:01 
Questionplease help me sm the chlbx items,pleeease Pin
nellyvb.net5-Jun-06 2:20
nellyvb.net5-Jun-06 2:20 
AnswerRe: please help me sm the chlbx items,pleeease Pin
Rey99995-Jun-06 2:38
Rey99995-Jun-06 2:38 
QuestionTextBox language !! Pin
Tamimi - Code5-Jun-06 1:07
Tamimi - Code5-Jun-06 1:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.