Cannot Reference my User Control from Code (vb.net)

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

Greetings,

I have a user control in my web form. I cannot reference it in code.

My HTML File has the header:
<%@ Register TagPrefix="PLB" Tagname="PIPSidebar"
src="ProjectListSidebar.ascx" %>

and references the User Control...
<PLB:PIPSIDEBAR id="PIPSIDEBAR1" runat="server"></PLB:PIPSIDEBAR>

It shows up in the page fine, but I cannot reference any properties from in
it. I am trying to reference the selected item of a listbox in the user
control with the following code...
PIPSIDEBAR1.ListBoxValue

but it doesn't recognize PIPSIDEBAR1 in vs.net or when I run the web
application. I just get the blue squiggly line under PIPSIDEBAR1.

By the way, my Property (within the ascx page to get the value of the
selected item) is below, but that doesn't seem to be the problem anyways.

Public ReadOnly Property ListBoxValue as String
Get
Return lst_ProjectNumName.SelectedItem.Value
End Get
End Property
 
Hello Dave,

In your codebehind file, make sure you have something like:

protected PIPSidebar myVariableName;

and then in Page_Load, you should be able to do string s = myVariableName.ListBoxValue;
 
Thanks for the advice. Where do I put the code below? What would that line
of code look like in vb? (Sorry, I'm not bilingual)
 
Hello Dave,

Im not bilingual either, but Ill try... :=)

In your code behind file, you should have a bunch of variable declarations.

One of those may already by something like:

Protected WithEvents myVariableName As PIPSideBar

Make sure that that exists and that you have a <PLB:PIPSidebar> in your aspx
file that has an ID with the same name as 'myVariableName' (ie: <plb:PIPSideBar
id="myVariableName' runat="server"/>)

Then, in your Page_Load method, you can do something like:

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
Dim myString As String = myVariableName.ListBoxValue
End Sub

Hope this works...
 
Back
Top