having a 100% working aspx page I wanted to create a user control from a
small DataList section (which has an ID="DataList1" ) of the page, so I
created an ascx file with the DataList and Register the control as should be
done. Now the DataList1 can't be found any more:
The name 'DataList1' does not exist in the current context
why's that?? 6 8615
if it helps, I see in the debugger that the control is not a child of the
page class... I had thought of using Page.FindContro l() - is that really
neccesary (instead of somehow making the control a child of the page
class???)
"Davids" <db****@simnet. is> wrote in message
news:co******** **@news.simnet. is... having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1" ) of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context
why's that??
"Davids" <db****@simnet. is> wrote in message
news:co******** **@news.simnet. is... having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1" ) of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context
why's that??
Because the .ascx file created a class. DataList1 is now a member of that
class.
John Saunders
To extend upon John's answer, you'll either need to expose the control
through a property of the class defined/by your .ascx OR change the
visibility modifier (VS.NET property: "Modifiers" ) of the control to public.
--
Dave Fancher http://davefancher.blogspot.com
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:OK******** *****@TK2MSFTNG P11.phx.gbl... "Davids" <db****@simnet. is> wrote in message news:co******** **@news.simnet. is... having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1" ) of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context
why's that??
Because the .ascx file created a class. DataList1 is now a member of that class.
John Saunders
"Dave Fancher" <ei*****@comcas t.net> wrote in message
news:RM******** ************@co mcast.com... To extend upon John's answer, you'll either need to expose the control through a property of the class defined/by your .ascx OR change the visibility modifier (VS.NET property: "Modifiers" ) of the control to public.
Neither of which is a good idea, in general.
You should probably reevaluate why you wanted the DataList to be in a .ascx
file. Exactly what do you want the .ascx file to look like to the pages its
living on? Among other things, you should probably hide the details of the
..ascx file from the pages using it. This implies that you do NOT want to
make the DataList directly accessible to the calling pages.
Keep in mind that you're in the realm of OO. You've created a class. Allow
it to hide its details from the world, and your code will be much more
reusable.
John Saunders "John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message news:OK******** *****@TK2MSFTNG P11.phx.gbl... "Davids" <db****@simnet. is> wrote in message news:co******** **@news.simnet. is... having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1" ) of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context
why's that??
Because the .ascx file created a class. DataList1 is now a member of that class.
John Saunders
So you put a DataList inside a UserControl? In that case, the DataList won't
be a child control of the Page class. Instead, it is a child control of the
UserControl. You will have to use the FindControl method to use it. You can
emulate the coding style that you would normally use with Page child
controls by adding this line below the set of Protected WithEvents lines
(assuming you're writing this in VB.net):
Private DataList1 as System.Web.UI.W ebControls.Data List =
MyUserControl.F indControl("Dat aList1")
Hooking up DataList events also becomes a problem. The best thing is to
handle the DataLists's events inside the UserControl. If you need to hook up
DataList events inside the Page class, you'll most likely have to expose the
DataList events as UserControl events. Reply back if this is the situation,
and I'll write up some working code for you!
Happy coding,
Johann MacDonagh
"Davids" <db****@simnet. is> wrote in message
news:co******** **@news.simnet. is... if it helps, I see in the debugger that the control is not a child of the page class... I had thought of using Page.FindContro l() - is that really neccesary (instead of somehow making the control a child of the page class???)
"Davids" <db****@simnet. is> wrote in message news:co******** **@news.simnet. is... having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1" ) of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context
why's that??
That's a good point. In some situations, where you have some core
functionality you want to reuse in several pages, it would be better off
creating a new server control that extends the functionality of the
DataList.
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message
news:ur******** ******@TK2MSFTN GP10.phx.gbl... "Dave Fancher" <ei*****@comcas t.net> wrote in message news:RM******** ************@co mcast.com... To extend upon John's answer, you'll either need to expose the control through a property of the class defined/by your .ascx OR change the visibility modifier (VS.NET property: "Modifiers" ) of the control to public.
Neither of which is a good idea, in general.
You should probably reevaluate why you wanted the DataList to be in a .ascx file. Exactly what do you want the .ascx file to look like to the pages its living on? Among other things, you should probably hide the details of the .ascx file from the pages using it. This implies that you do NOT want to make the DataList directly accessible to the calling pages.
Keep in mind that you're in the realm of OO. You've created a class. Allow it to hide its details from the world, and your code will be much more reusable.
John Saunders
"John Saunders" <johnwsaundersi ii at hotmail.com> wrote in message news:OK******** *****@TK2MSFTNG P11.phx.gbl... "Davids" <db****@simnet. is> wrote in message news:co******** **@news.simnet. is... having a 100% working aspx page I wanted to create a user control from a small DataList section (which has an ID="DataList1" ) of the page, so I created an ascx file with the DataList and Register the control as should be done. Now the DataList1 can't be found any more: The name 'DataList1' does not exist in the current context
why's that??
Because the .ascx file created a class. DataList1 is now a member of that class.
John Saunders
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: adiel |
last post by:
Hello, I am trying to access the properties and methods from a user
control within the code-behind file for a webform but I am receiving
the message:
Name 'MenuBar1' is not declared
It does not recognize the user control in the code behind...
Here is the code for the user control:
MenuBar.ascx:
|
by: Brian W |
last post by:
Hi All,
I have a web user control that, among other things, provides Print this
page, and Email this page functionality I have this script that is to
execute on the click of the asp:hyperlinks
I have a function in a <SCRIPT> block that I want in the <head></head>
section of the page. Unfortunately, RegisterClientScriptBlock,
RegisterStartupScript don't always work, and when they do the script is
placed inside the <form> tag (this...
|
by: Dan |
last post by:
We have a simple site. It's a frameset with two frames a left and a right.
The left frame is essentially a list of records from a database (using a
server-side repeater control). When you click on one of the items in the
left frame, it targets the right frame and displays a form prefilled with
information for the item you clicked.
The problem is the left frame's list just shows the names of the items, and
the name of the item is...
|
by: William Parker |
last post by:
I have a web control I made called header.ascx. It has its own properties
and methods I defined. But I cannot figure out how to access this control
from my code behind page.
I can create the web control just fine and script with it as needed from the
webform1.aspx page itself just fine, like this:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
Inherits="mysite.WebForm1" %>
<%@ Register TagPrefix="uc1"...
|
by: Ryan Taylor |
last post by:
Hi.
I need to be able to access a public code behind variable within my ASPX
page. The reason is that I have a user control "Header" which defines a
table layout, and is included in all my pages, at various levels in the
website heirarchy. The table requires a background image. My images folders
is at the root of the website, effectively "~/images/". I need the
background image to show whether I at a page in the root of my website or in...
| |
by: Ric |
last post by:
im new to asp.net. from what i understand, you have the aspx file
(presentation), user-control(ascx file), code-behind(vb file) and
components(compiled vb and dll files). the aspx file contains a
reference to the ascx which can contain a reference to a component.
can an aspx file contain a reference to an ascx file which contains a
reference to a code-behind file? ive tried to do this then load the
user-control via LoadControl(), but i...
|
by: N. Demos |
last post by:
I have a user control with code behind of which two instances are
created/declared in my aspx page. The aspx page has code behind also, as
I need to access methods of the usercontrols on page submit.
I've read several post here and articles on the web on this topic. What
little I have learned from them is that you have to pre-compile the
usercontrol in order to access it in the aspx code behind. I did this,
compiling the usercontrol...
|
by: zhuang |
last post by:
When we drag and drop any server control from toolbox to web form, the
relevant control is added to code-behind automatically with access
level to be protected.
When we drag and drop a user control to a web form, if we want to use
that user control in code-behind, then we need to declare it to be
protected as well, otherwise it will not work properly, why???
I never pay attention to this untill I start to work with user control.
|
by: rn5a |
last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with
the IDs 'txt1' & 'txt2' respectively. To use this user control in an
ASPX page, the following Register directive will be required:
<%@ Register TagPrefix="UC" TagName="MyUserCtrl" Src="MyUC.ascx" %>
Assuming that the ASPX page doesn't use a code-behind, I can access the
properties, events etc. of the user control in the ASPX page in this
way (assume that the ASPX page...
|
by: bradwoody |
last post by:
ASP.Net and C#
I am having trouble determining how to manipulate html controls via javascript AND access those same controls in the C# code behind. Here's the scoop:
I am making an advanced search page, consisting of a table where each row has (in this order):
- checkbox – to indicate whether to return the column
- label
- textbox – to enter search criteria
On some rows, though, I replaced the textbox with radio buttons so...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |