ASP.Net user control

  • Thread starter Thread starter RCIC
  • Start date Start date
R

RCIC

If I add a user control to a webform, it seems like I
should be able to make it visable or invisable. My code
doesn't seem to work. I made a control called myControl
and dragged to on to my web form. I then added this to
the code behind and ran it.

Public test As myControl

Private Sub Page_Load(ByVal sender .....
test.Visible = False
End Sub

The error I get is: Object reference not set to an
instance of an object. Any idea what my problem is?
 
When you add the user control to the web form it places
references in the HTML:

At the top of the HTML Document
<%@ Register TagPrefix="uc1" TagName="ucpager"
Src="UserControls/ucPager.ascx" %>

And at the place where you added the control
<TD>
<uc1:ucpager id="PageHeaderControl"
runat="server"></uc1:ucpager>
<TD>

what you need to do is add a reference in the code behind
as follows:

protected namespace.controltype controlname
where control name matches the ID in the HTML so in the
example above:
protected namespacewhatever.ucpager PageHeaderControl


now you can access the properties i.e.
PageHeaderControl.Visible
 
Back
Top