views:

37

answers:

1

I have some common code that I would like to share between pages and I have been messing around with App_Code classes which is great but I would also like to use code that affects drop down lists example:

Sub Set_FirmType(ByVal Sender As Object, ByVal E As EventArgs)

    subcategories.Visible = "false"
    supplycategories.Visible = "false"
    supplytypes.Visible = "false"
    CityData.Visible="True"
    CityDropDown.Visible="False"
    CityDropDown.Items.Clear()

    If DropFirmType.SelectedValue = "funeralhomes||FH" Then
        CountryDropDown.ClearSelection()
        CountryDropDown.Items.FindByValue("United States").Selected = True
        CountryDropDown.Enabled = False
        StateDropDown.Enabled = True
        getStateDropDown("1")
    End If
End Sub

Is their a way to put this in my App_Code class?

Thanks in advance!

+1  A: 

It sounds like you have a sub-routine that is toggling visibility on multiple controls and setting some properties on a drop down list. You may want to consider packaging all of the controls into a single user control (.ascx) and putting the sub-routine in the code behind.

Housing the user control in the App_Code folder is not necessary for reuse across the application. Just drop the user control onto pages where you want the functionality.

Ben Elder
Agreed. I would recommend this approach, or alternatively inheriting a class from the System.Web.UI.DropDownList class and extending it that way. +1
Kyle B.