Navigation:


FORUMS > SentryFile Version 5 Topics > SF5 - API Integration / Programming Assistance < refresh >
Topic Title: Persisting Dynamic Controls
Created On Tue October 22, 2013 11:13 AM
Topic View:

View thread in raw text format


hmitchell

Posts: 7
Joined: Aug 2013

Tue October 22, 2013 11:13 AM
User is offline

Within my vb.net application, I want to provide a SentryFile cabinet search capability. I create dynamic controls based on the values returned from RepositoryFieldList (i.e.: Text and number = TextBox, Lookup = DropDownList). I cannot persist the entered/selected values across PostBack - I recreate the controls themselves using ViewState, but I can't come up with a way to retain the values.
The only other way I can think to do this is to hide a number of TextBoxes and DropDownLists on the page and make them visible as needed.
I thought I would have to do it this way since different cabinets have different filed lists.
Has anyone done anything like this or have a suggestion for a better way to handle this?
Thanks


-------------------------
DotNet, MS/SQLServer
 
Reply
   
Quote
   
Top
   
Bottom
     



SupportRep

Posts: 6587
Joined: Feb 2004

Tue October 22, 2013 5:47 PM
User is offline

Hi,

What type of controls are you using to store the Repository Field List? Most asp.net controls persist data across postbacks. Is it possible that you have an "onload" event which is reloading your dynamic controls? (Essentially, flushing and reloading those controls on postback?) You might be able to check for a postback (page.ispostback) and not reload those controls under postback conditions.

Give us some more details and we'll try to point you in the right direction!

Thanks!

-------------------------
-SentryFile Support
 
Reply
   
Quote
   
Top
   
Bottom
     



hmitchell

Posts: 7
Joined: Aug 2013

Wed October 23, 2013 8:30 AM
User is offline

Thanks for your reply.

I store the results for RepositoryFieldList in a datatable. For each row in the datatable I execute the attached code (ix is a Class level integer, pnlCriteria is the container panel for the added controls, GetLookupValues is a function that returns a datatable for the dropDownList values). A search button clicked event fires the actual search.

I save the repository_id in the ViewState and retrieve it on PostBack to recreate the dynamic controls, however I cannot reference the events for the dynamic controls to retrieve the tb??.text or the ddl??.selectedValue.

If a solution for this can be found, that would be great; if not, I will just hide 5 or so textBoxes and dropDownLists on the page and make them visible as needed (the downside of this approach is that a recompile would be necessary if more controls are needed).

Thanks for your help!

    Private Sub ProcessDatatable(ByVal dt As DataTable)
        For Each dr As DataRow In dt.Rows
            Dim lit, lit2 As New Literal
            lit.Text = "<div class='row'>"
            lit2.Text = "</div>"
            Me.pnlCriteria.Controls.Add(lit)

            AddSearchField(dr("field_id") _
                           , dr("field_name") _
                           , dr("field_description") _
                           , dr("field_type") _
                           , dr("field_required") _
                           , dr("field_search") _
                           , dr("field_unique"))

            Me.pnlCriteria.Controls.Add(lit2)

        Next

    End Sub

    Private Sub AddSearchField(ByVal field_id As Integer, _
                               ByVal field_name As String, _
                               ByVal field_description As String, _
                               ByVal field_type As String, _
                               ByVal field_required As Boolean, _
                               ByVal field_search As Boolean, _
                               ByVal field_unique As Boolean)
        Dim labelName As New Label
        labelName.Text = field_name.ToUpper
        Me.pnlCriteria.Controls.Add(labelName)
        Select Case field_type.ToLower
            Case "text"
                Dim tb As New TextBox
                tb.ID = "tb" + ix.ToString()
                Me.pnlCriteria.Controls.Add(tb)
                ix += 1
            Case "number"
                Dim tb As New TextBox
                tb.ID = "tb" + ix.ToString()
                Me.pnlCriteria.Controls.Add(tb)
                ix += 1
            Case "lookup"
                Dim ddl As New DropDownList
                ddl.ID = "ddl" + ix.ToString()
                Dim ddlName As String = ddl.ID
                Dim dt As DataTable = GetLookupValues(field_id)
                For Each dr As DataRow In dt.Rows
                    ddl.Items.Add(dr("lookup_value"))
                Next
                Me.pnlCriteria.Controls.Add(ddl)
                ix += 1
        End Select

    End Sub


-------------------------
DotNet, MS/SQLServer

 
Reply
   
Quote
   
Top
   
Bottom
     



SupportRep

Posts: 6587
Joined: Feb 2004

Wed October 23, 2013 10:29 AM
User is offline

Hi,

Yeah, this is a problem that virtually all asp.net developers face when building complex interfaces. I think you're probably going to create those hidden text boxes, or alternatively save the values in the session state.

Sorry, wish I knew a better way of doing this...

Let us know if you need any other help!

Thanks,

-------------------------
-SentryFile Support
 
Reply
   
Quote
   
Top
   
Bottom
     

View thread in raw text format
FORUMS > SentryFile Version 5 Topics > SF5 - API Integration / Programming Assistance < refresh >

Navigation:

FuseTalk 4.0 © 1999-2003 FuseTalk Inc.