473,396 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How does user controls's instances work?

Hi,

I have my user control called: WebUserControl1.ascx

I have my web page called: WebForm1.aspx

I drag WebUserControl1.ascx to WebForm1.aspx.

The following tags were added to my page:

<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="WebUserControl1.ascx" %>

<uc1:WebUserControl1 id="WebUserControl11"
runat="server"></uc1:WebUserControl1>

Now, I want to call a method on the control instance
"WebUserControl11", I use this code on my web page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

------> WebUserControl11.RefreshControlData() <-----

End Sub

Error, WebUserControl11 is not declared, it doesn't exists on my page
scope.

What I'm missing here or what I don't understand...why I can't access
the control instance in my code part of page?

Best Regards
Fabio

Nov 19 '05 #1
2 1037
Hi Fabio,

In your code behind class for the page, you need to declare a protected
variable for the control.

Give it the same name and type as the control. Sorry, but I don't know the
Syntax for VB, but for C#, it would be:

protected WebUserControl1 WebUserControl11;

So in VB, it might be something like (I'm just guessing)
dim protected WebUserControl11 as WebUserControl1;

Once you do that, ASP.NET will create the instance based on the ASPX page's
control. It is important that they are named the same.

HTH

Steve

<ca********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi,

I have my user control called: WebUserControl1.ascx

I have my web page called: WebForm1.aspx

I drag WebUserControl1.ascx to WebForm1.aspx.

The following tags were added to my page:

<%@ Register TagPrefix="uc1" TagName="WebUserControl1"
Src="WebUserControl1.ascx" %>

<uc1:WebUserControl1 id="WebUserControl11"
runat="server"></uc1:WebUserControl1>

Now, I want to call a method on the control instance
"WebUserControl11", I use this code on my web page:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

------> WebUserControl11.RefreshControlData() <-----

End Sub

Error, WebUserControl11 is not declared, it doesn't exists on my page
scope.

What I'm missing here or what I don't understand...why I can't access
the control instance in my code part of page?

Best Regards
Fabio

Nov 19 '05 #2
Great! I know that this should be very simple

Thanks Steve, this was annoying Me

Best Regards
Fabio

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: zapazap | last post by:
Dear Snake Charming Gurus, (Was: http://mail.python.org/pipermail/python-list/2004-January/204454.html) First, a thank you to Tim Golden, Thomas Heller, and Mark Hammond for your earlier help...
4
by: Brian Glen Palicia | last post by:
My goal is to accept input from the user into a text box and then parse the data using split(). The first step is this tiny program to test the split() function. It runs in IE, but in Mozilla it...
1
by: TIM T | last post by:
I want to load a user control from a dll dynamically to my main form. I have been reading about using reflection. I got this to work with the methods from my other classes in the dll but I am not...
10
by: BBM | last post by:
Hi, I have been developing with C# User Controls and occasionally have a problem where I "lose" a control from the design surface of the User Control. The controls that I am using to build my...
1
by: David J. Berman | last post by:
Thanks for any help...! My error is: Object reference not set to an instance of an object. > public int DisplayOrder { > get { >>>>>> return (int) ViewState; > }
2
by: Sam Kuehn | last post by:
There has been a lot of articles on how to load user controls at runtime in the Init() method. UserControl myControl = (UserControl)LoadControl(stringControl); I add the control in the Init()...
17
by: Barret Bonden | last post by:
As an old programmer just now looking at VB.net I have a question: How does one simply open one form from another ? I don't mean how does one create a new instance of that form , but rather how...
17
by: B. Chernick | last post by:
I'm trying to create a web page and I need a javascript function to be called on the load of a particular panel. (The panel is hidden during some but not all postbacks.) The function is bound...
14
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it...
2
by: Moistly | last post by:
Hi everyone, This is a scenerio for my problem, I have one aspx page with several instances of the same Web User Control (ascx files). I have for example the Web User Control that has a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.