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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Usercontrol-properties from aspx-codebehind

Status
Not open for further replies.

KenniM

Programmer
Nov 27, 2002
25
DK
I've been trying to get help on this issue for a while now but still after reading everything and trying everything(nearly:D) I'm asking your help.

The problem is the same for many others. I have my UserControl consisting of an ascx and ascx.vb file. The userControl is Registered and used in my aspx file. But when I want to access its properties i can not do that from the ascx-code-behind file. It works fine if i put all the code in the aspx file.

I've read that you should define/declare the usercontrol in the codebehind file as something like:

Protected WithEvents MyControl As (type). And this is where it stops for me. What should i write as type. My control is a SiteHeader type of control, but it doesn't work if i write "As SiteHeader". There must be some referencing problem.

I'm in need of help here. PLease explain this to me and please do not post some hyperlink - I've been there and it looks easy - but still I can't get it to work :D

Thank you.
Kenni
 
Sorry I ment that I cant access it from the ASPX-code-behind file. :D
 
i do:
Code:
Public MyControl as Object

keep in my you may need to have properties declared in your usercontrol to actually access data from it.

ie, my control has
Code:
Public readonly Property SelectedValue() as String
    Get
        SelectedValue= SomeDropDownList.SelectedItem.Value
    End Get
End Property

then in your codebehind for the page you can say:
Code:
something = MyControl.SelectedValue

hope this helps.
 
Thank you gagz, this was exactly what i needed. My problem was that i didn't know what I should define the MyControl as. Defining it as an Object made it work.

Now I'm able to use both methods and properties of the MyControl's Codebehind Class. :D

Kenni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top