Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

declare user control in aspx page

Status
Not open for further replies.

jjmendo

Programmer
Feb 7, 2005
7
US
I've created a user control consisting of a dropdownlist. I've also set the property in the dropdownlist. Now I need to get the value of the dropdownlist in the main page's code-behind page. Can anyone tell me how to delcare the user control in the code-behind. I've tried Protected UCState1 As StateBind where UCState1 is the dropdownlist ID and StateBind is the class for the usercontrol codebehind.

 
hmm,

Little bit vague but here you go. If you have a Control on your Page that you want to access on the code behind you have to find it then Cast it to the type of your ccontrol then you can use it. like this:

Code:
Dim ctl As Control = FindControl("YourControlID")
Dim myControl As YourControlClass
 myControl = DirectCast(ctl, ReportMenu)
 myControl.yourparameter1 = "somestuff" 
 myControl.YourParameter2 = 104

Hope that helps

bassguy
 
Get Error: Type 'Control' is not defined

I've imported the following:
Imports System.Web.UI.WebControls
Imports System.Web.UI.UserControl
Imports System.Web.UI.Control
 
K, I've Imported System.Web.UI and type "Control" resolved.

But 'Dim myControl As StateBind' get StateBind not defined.

Here's the code for my usercontrol codebehind:

Imports System
Imports System.Web.UI.WebControls

Public Class StateBind
Inherits System.Web.UI.UserControl
Public WithEvents ddlState As DropDownlist

Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim sStates() As String = "", "AK", "AL"}
ddlState.Datasource=sStates
ddlState.DataBind()
End If
End Sub

Public Property selState As String
Get
Return ddlState.SelectedItem.Text
End Get
Set
ddlState.Items.FindByText(value).Selected = True
End Set
End Property
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top