[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

VB.net Sharepoint 2010 Application -- Allow Simultaneous Instances

I am developing a sharepoint 2010 webpart with VB.net 2010.  The application created text boxes dynamically depending upon user input.  This works fine as long as there is only one instance of the web part running after deployment.  However, If I try to run two separate instances from two separate computers simultaneously I get an error stating that "FindControl requires that controls have unique IDs".  I understand why that error is occurring, but I'm not sure how to avoid it.  Is there a way that I can have two instances running at the same time?  Does it have anything to do with the "EnableSessionID" property?  If so, where do I make the appropriate changes.  I tried setting EnableSessionID = True in the Web.config file of the sharepoint site, but I still have the same problem.  I feel like I'm missing something simple.  

Thanks In Advance!
0
Phoenix1970
Asked:
Phoenix1970
  • 6
  • 2
1 Solution
 
CodeCruiserCommented:
Can you show us the code which creates textboxes?

I suspect you are creating textboxes with names that may be unique if you only use one instance but would be duplicate if more than one instance of webpart is added. You can use a GUID or use the webpart ID in the naming of the textboxes to make the names unique.
0
 
Phoenix1970Author Commented:
Thanks CodeCruiser for the response.  I was able to figure out how to create a GUID and assign that value to the ID property of the text boxes and other controls.  I am no longer receiving the error message when I have multiple instances of the application open at the same time.  However, these text boxes are being created on the click event of a button.  I also have list boxes that are being populated on the click event of this button as well.  If I have the application open on two computers and click that button on each, the instance in which I click the button the second time will have twice as many text boxes and the list boxes will be populated twice.   How can I prevent this?  I hope that made sense
0
 
CodeCruiserCommented:
I will need to see the code that is creating the textboxes then.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Phoenix1970Author Commented:
I've included the code for the click event of the button, for populating the drop down lists, and the creation of the textboxes.  

 Protected Sub btnNext_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNext.Click

        HideOriginalControls()
        BuildSpecPage.ShowSpecControls()
        BuildSpecPage.AssignControls()
        BuildSpecPage.AssignGuidToControls()
        Submittal.Controls.Add(tblOne)
        Submittal.Controls.Add(tblTwo)

        'populate associated tasks check box list
        PopulateAssociatedTaskList()

        'Populate Priority drop down list
        PopulatePriorityList()

        'Populate WO Type drop down list
        PopulateWOTypeList()

        'Populate Requested By drop down list
        PopulateRequestedByList()

    End Sub

    Private Sub PopulateAssociatedTaskList()

        'Declare Variables
        Dim mrGetTasks As New MR_SQL

        'Dim arrTasks As New ArrayList    
        Dim dblCount As Double
        Dim strEqno As String
        Dim strListItem As String
        Dim bolDataExists As Boolean = False

        strEqno = lblEqno.Text
        arrGetTask = mrGetTasks.MR_GetJobTasks(strEqno)

        'Assign value to count for loop to add items to check box
        dblCount = (arrGetTask.Length / 3) - 1

        For i = 0 To Convert.ToInt32(dblCount)

            strListItem = arrGetTask(i, 0) & " " & arrGetTask(i, 1) ' Populate string with array item by index 
            intListcount = cblTasks.Items.Count - 1 ' Increments every loop, used to check duplicate records 

            'Add first extracted record to check box 
            If cblTasks.Items.Count = 0 Then
                cblTasks.Items.Add(strListItem)
                bolDataExists = True
            End If

            'Check for duplicate records 
            For n = 0 To intListcount
                If strListItem = cblTasks.Items(n).Text Then
                    bolDataExists = True
                    Exit For
                End If
            Next

            'do not add duplicate records to check list
            If bolDataExists = False Then
                cblTasks.Items.Add(strListItem)
            Else
                bolDataExists = False
            End If
        Next

        'Populate List count variable and create text boxes for comments
        intListcount = cblTasks.Items.Count
        CreateCommentTextBoxes(intListcount)

    End Sub
    Private Sub PopulatePriorityList()

        ddlPriority.Items.Add("ROUTINE")
        ddlPriority.Items.Add("STANDARD")
        ddlPriority.Items.Add("URGENT")
        ddlPriority.Items.Add("PRESS WAITING")

    End Sub
    Private Sub PopulateWOTypeList()

        'Declare Variables
        Dim mrWOType As New MR_SQL
        Dim arrGetWOType As String()
        Dim arrWOType As New ArrayList
        Dim dblCount As Double
        Dim strListItem As String

        arrGetWOType = mrWOType.MR_GetPMWOType()

        dblCount = arrGetWOType.Length - 1

        For i = 0 To Convert.ToInt32(dblCount)
            strListItem = arrGetWOType(i)
            ddlWOType.Items.Add(strListItem)
        Next

    End Sub

    Private Sub PopulateRequestedByList()

        Dim mrGetEmp As New MR_SQL
        Dim arrGetEmp As String(,)
        Dim arrEmp As New ArrayList
        Dim dblCount As Double
        Dim strListItem As String

        arrGetEmp = mrGetEmp.GetEmployeeNames()
        dblCount = (arrGetEmp.Length / 2) - 1

        For i = 0 To Convert.ToInt32(dblCount)
            strListItem = arrGetEmp(i, 0) & ", " & arrGetEmp(i, 1)
            ddlReqestedBy.Items.Add(strListItem)
        Next

    End Sub
Public Sub CreateCommentTextBoxes(ByVal Count As Integer)

        ReDim txtCommentArray(Count)

        For i = 0 To Count - 1
            txtComment = New TextBox
            txtComment.Width = 300
            txtComment.ID = strGUID & i.ToString
            txtCommentArray(i) = txtComment
        Next

        For i = 0 To Count - 1
            pnlComment.Controls.Add(txtCommentArray(i))
        Next

    End Sub

Open in new window

0
 
Phoenix1970Author Commented:
Do I need to provide more information?
0
 
Phoenix1970Author Commented:
Actually, don't worry about it.  I figured it out.  Had to do with post back.  My controls were being created and populated multiple times.  Thanks anyway
0
 
Phoenix1970Author Commented:
I'll have to admit, even though I said not to worry about it and I answered my own question, I would have expected some kind of response/acknowledgement by now.  I've always regarded this site as more "professional" than some of the others.  Also,  it cost me money to post this question.  That simple fact alone should motivate the "experts" to be more responsive and concerned for my issues.  I ended my subscription months ago because I wasn't using the site.  I'm regretting the fact that I renewed it.
0
 
Phoenix1970Author Commented:
This is the best solution because I have concluded that I will not be coming to this site for solutions anymore.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now