471,073 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,073 software developers and data experts.

ASP.Net user control

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?
Jul 21 '05 #1
1 1225
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
-----Original Message-----
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?
.

Jul 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by martin | last post: by
4 posts views Thread by louise raisbeck | last post: by
2 posts views Thread by rn5a | last post: by
3 posts views Thread by Fred Chateau | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.