Passing Properties in user controls

B

Bob Avallone

I have created a user control (aspc). I want the user of
the control (aspx) to be able to pass a property to the
control at runtime. I think I'm close but I don't have it
quite right.

Here are the key portions of the code.

From the ascx module:

Public gstrTitle As String


Code from the aspx module


<%@ Register TagPrefix="uc1" TagName="Calendar"
Src="Calendar.ascx" %>
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="WebForm1.aspx.vb"
Inherits="MetaProSystems.GeneralCalendarControl.WebForm1" %

Protected WithEvents uctCalendar As Calendar


Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
uctCalendar.Visible = True
uctCalendar. gstrTitle = "My Title"

End Sub

gstrTitle is recognized by intellisense .When I step
through the code uctCalendar is set to nothing so
naturally I get an error

Object reference not set to an instance of an object
 
S

Svetlin Grancharov

Hi,
In Aspx page you should set ID (like the variable you have
used in the code) on your user controls. I mean you should
use your controls with something like
<uc1:Calendar id="uctCalendar" runat="server"/>

After that you code should work.

Regards,

Svetlin Grancharov
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top