Having trouble with dynamic controls on my ASP.Net web site

soniapeach

New Member
I have an asp.net web page which is giving me some problems. I developed the following classes to generate search filters for the page. The search process is not important as it already works. I want to dynamically generate the search filters.\[code\]Imports Microsoft.VisualBasicImports System.Collections.GenericImports System.Collections.ObjectModelImports MEI.SPDocuments.TypePublic Class SearchFilter Private WithEvents _genreDropDown As DropDownList Private WithEvents _subGenreDropDown As DropDownList Private WithEvents _txtValue As TextBox Private _txtBoxAutoCompleteExtender As AjaxControlToolkit.AutoCompleteExtender Private _filterGenres As Collection(Of String) Private _programSubGenres() As String = {"Program ID,GetPrograms", "Territory ID,GetTerritories", _ "Rep Name,GetRepNames", "District ID,GetDistricts", "DM Name,GetDMNames", "Region ID,GetRegions", _ "RM Name,GetRMNames", "Speaker Counter,GetSpeaker", "Vedor ID,GetVendors", "Vendor Name,GetVendorName", _ "Date Range,", "City,", "State,", "Pay To,", "Expense Range,", "PIF ID,GetPifs"} Private _speakerSubGenres() As String = {"Speaker Counter,GetSpeaker", "Speaker Last Name,GetSpeakerLNames", "Speaker First Name,GetSpeakerFNames"} Private _expenseSubGenres() As String = {"Expense Counter,GetExpenses"} Private _vendorSubGenres() As String = {"Vendor ID,GetVendors", "Vendor Name,GetVendorName"} Private _trackSubGenres() As String = {"Track Number,GetTracks", "HCP First Name,GetHCPFName", "HCP Last NameGetHCPLName"} Public Sub New(ByVal company As CompanyCode, ByVal year As DocumentYearCode) _filterGenres = New Collection(Of String) _txtValue = http://stackoverflow.com/questions/12646264/New TextBox _txtValue.ID = Guid.NewGuid.ToString _txtBoxAutoCompleteExtender = New AjaxControlToolkit.AutoCompleteExtender With _txtBoxAutoCompleteExtender .ID ="AC__" + _txtValue.ID .MinimumPrefixLength = 1 .EnableCaching = False .ServicePath = "~/AutoComplete.asmx" .ServiceMethod = "PlaceHolder" .TargetControlID = _txtValue.ID .CompletionListCssClass = "CompletionList" .CompletionListHighlightedItemCssClass = "ItemHighlighted" .CompletionListItemCssClass = "ListItem" .DelimiterCharacters = "" .Enabled = True End With Select Case company Case CompanyCode.AbbottAnimalHealth, CompanyCode.AbbottDiabetesCare, CompanyCode.AbbottDiagnosticsDivision, CompanyCode.AbbottMedicalOptics, CompanyCode.AbbottMolecular, _ CompanyCode.AbbottPointOfCare, CompanyCode.AbbottVascular, CompanyCode.Corporate, CompanyCode.DivAbbottNutrition, CompanyCode.EstablishedProductsDivision, _ CompanyCode.GlobalPharmaceuticalResearchAndDevelopment, CompanyCode.GlobalStrategicMarketingAndServices, CompanyCode.PharmaseuticalProductsGroup, _ CompanyCode.ProprietaryPharmaceuticalsDivision, CompanyCode.RegulatoryAffairsPPG _filterGenres.Add("Div Docs") Case Else _filterGenres.Add("Program") _filterGenres.Add("Speaker") _filterGenres.Add("Expense") _filterGenres.Add("Vendor") End Select _genreDropDown = New DropDownList _genreDropDown.AutoPostBack = True _genreDropDown.Attributes.Add("runat", "server") AddHandler _genreDropDown.SelectedIndexChanged, AddressOf _genreDropDown_ItemChanged _subGenreDropDown = New DropDownList _subGenreDropDown.AutoPostBack = True _subGenreDropDown.Attributes.Add("runat", "server") AddHandler _subGenreDropDown.SelectedIndexChanged, AddressOf _subGenreDropDown_ItemChanged PopulateDDls()End SubPrivate Sub PopulateDDls() _genreDropDown.Items.Add("") For Each s As String In _filterGenres _genreDropDown.Items.Add(s) NextEnd SubPrivate Sub _genreDropDown_ItemChanged(ByVal sender As Object, ByVal e As System.EventArgs) _subGenreDropDown.Items.Clear() _subGenreDropDown.Items.Add("") Select Case _genreDropDown.SelectedItem.ToString Case "Program" For Each s As String In _programSubGenres Dim li As New ListItem(s.Split(CChar(","))(0), s.Split(CChar(","))(1)) _subGenreDropDown.Items.Add(li) Next Case "Speaker" For Each s As String In _speakerSubGenres Dim li As New ListItem(s.Split(CChar(","))(0), s.Split(CChar(","))(1)) _subGenreDropDown.Items.Add(li) Next Case "Expense" For Each s As String In _expenseSubGenres Dim li As New ListItem(s.Split(CChar(","))(0), s.Split(CChar(","))(1)) _subGenreDropDown.Items.Add(li) Next Case "Vendor" For Each s As String In _vendorSubGenres Dim li As New ListItem(s.Split(CChar(","))(0), s.Split(CChar(","))(1)) _subGenreDropDown.Items.Add(li) Next Case "Div Docs" For Each s As String In _trackSubGenres Dim li As New ListItem(s.Split(CChar(","))(0), s.Split(CChar(","))(1)) _subGenreDropDown.Items.Add(li) Next End SelectEnd SubPrivate Sub _subGenreDropDown_ItemChanged(ByVal Sender As Object, ByVal e As System.EventArgs) _txtBoxAutoCompleteExtender.ServiceMethod = _subGenreDropDown.SelectedValue.ToString If _subGenreDropDown.SelectedValue.ToString = String.Empty Then _txtBoxAutoCompleteExtender.ServiceMethod = "PlaceHolder"End SubPublic Function createMyTableRow() As HtmlTableRow Dim myRow As New HtmlTableRow myRow.Cells.Add(New HtmlTableCell()) myRow.Cells.Add(New HtmlTableCell()) myRow.Cells.Add(New HtmlTableCell()) myRow.Cells(0).Controls.Add(_genreDropDown) myRow.Cells(1).Controls.Add(_subGenreDropDown) myRow.Cells(2).Controls.Add(_txtValue) myRow.Cells(2).Controls.Add(_txtBoxAutoCompleteExtender) Return myRowEnd FunctionPrivate Sub newAutoCompleteExtender(ByVal genre As String) If _txtValue.Parent.Controls.Count = 2 Then _txtValue.Parent.Controls.RemoveAt(1) End If _txtValue.Parent.Controls.Add(_txtBoxAutoCompleteExtender)End SubEnd ClassPublic Class SearchFilterGroupPrivate _searchFilterCollection As Collection(Of SearchFilter)Private _tableContainer As HtmlTablePrivate _company As CompanyCodePrivate _year As DocumentYearCodePublic WithEvents _addFilterButton As New ButtonPublic Sub New(ByVal company As CompanyCode, ByVal year As DocumentYearCode) _searchFilterCollection = New Collection(Of SearchFilter) _tableContainer = New HtmlTable _company = company _year = year _addFilterButton.Text = "Add Filter" _addFilterButton.Attributes.Add("runat", "server") _addFilterButton.ID = "btnAddFilter" AddHandler _addFilterButton.Click, AddressOf _addFilterButton_ClickEnd SubPublic Sub _addFilterButton_Click(ByVal Sender As Object, ByVal e As System.EventArgs) _searchFilterCollection.Add(New SearchFilter(_company, _year)) _tableContainer.Rows.Add(_searchFilterCollection(_searchFilterCollection.Count - 1).createMyTableRow)End SubPublic Function table() As HtmlTable _tableContainer.Rows.Add(New HtmlTableRow) _tableContainer.Rows(0).Cells.Add(New HtmlTableCell) _tableContainer.Rows(0).Cells(0).ColSpan = 3 _tableContainer.Rows(0).Cells(0).Controls.Add(_addFilterButton) _addFilterButton_Click(Nothing, Nothing) _addFilterButton_Click(Nothing, Nothing) Return _tableContainerEnd FunctionEnd Class\[/code\]I am having problems devising a way to persist the generate controls. Any help would be appreciated.
 
Back
Top