Interaction between User Controls

  • Thread starter goalizx Goalizx
  • Start date
G

goalizx Goalizx

Hi!

I have two user controls. One of them was loaded
dynamically("quest.ascx"), and the other one declarative("menu.ascx").
Both are in the same Page.
So, how could I access to the values of "menu.ascx" control, from
"quest.ascx"?.

In the "menu.ascx" I have the GET PROPERTY as:
Protected withevents state As HtmlInputHidden

Public Property strState() As String
Get
Return CStr(state.Value)
End Get
End Property

I have tried to access it from "quest.ascx" as following:

Protected withevents menu As App.menu
'Protected withevents menu As New App.menu

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(menu.strState)
End Sub

This is the error displayed:

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.

I understand the error, how could I write the correct instance of the
object?

Is there anybody could help me??
thx a lot
 
K

Karl

They both share the Page in common, so use that to broker the relationship.

your page should have:

protected menuId as TypeOfYourMenuUserControl
public readonly property Menu as TypeOfYourMenuUserControl
get
return menuId
end get
end property


You can then easily access it in your quest.ascx via:

TypeOfYourMenuUserControl menu = Ctype(Page, TypeOfYourPage).Menu

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top