473,385 Members | 1,843 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,385 software developers and data experts.

using a User Control

SAL
Hello,

I created a WebPage.aspx that has some functions in it, and I created a User
Control that has a File Field Control and a Botton control on the .ascx. I
added myUserControl.ascx to the WebPage.aspx, but it can not access the
WebPage.aspx functions.

If I add a button to the WebPage.aspx, I can access those functions no
problem. Is not adding a User Control the samething? If not, what must I do
in myUserControl.ascx file so I can access the functions that are on the
WebPage.aspx where I placed myUserControl.ascx?

Thanks,
Oct 5 '06 #1
4 1372
when you think about it, your button can not access any of the page members.
You're writing page code that accesses the button.

Since your page code should not contain any logic at all, this might be a
sign that you need to break out some functionality into some seperate classes

"SAL" wrote:
Hello,

I created a WebPage.aspx that has some functions in it, and I created a User
Control that has a File Field Control and a Botton control on the .ascx. I
added myUserControl.ascx to the WebPage.aspx, but it can not access the
WebPage.aspx functions.

If I add a button to the WebPage.aspx, I can access those functions no
problem. Is not adding a User Control the samething? If not, what must I do
in myUserControl.ascx file so I can access the functions that are on the
WebPage.aspx where I placed myUserControl.ascx?

Thanks,
Oct 5 '06 #2
The user control should not be accessing functions that exist in the main
web page. User controls are encapsulated logic. Basically, you build them to
re-use in lots of different places. Because of this, you don't want them
trying to access functionality on a page. They can inform the page of
certain events through event bubbling, and you can access properties and
methods of the user control from the page, but you don't want to do it the
other way around. It's just like the button control. You place the button
control and you can access the properties and methods of the button. The
button does not access the page code itself and perform any tasks.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"SAL" <SA*@discussions.microsoft.comwrote in message
news:AF**********************************@microsof t.com...
Hello,

I created a WebPage.aspx that has some functions in it, and I created a
User
Control that has a File Field Control and a Botton control on the .ascx.
I
added myUserControl.ascx to the WebPage.aspx, but it can not access the
WebPage.aspx functions.

If I add a button to the WebPage.aspx, I can access those functions no
problem. Is not adding a User Control the samething? If not, what must I
do
in myUserControl.ascx file so I can access the functions that are on the
WebPage.aspx where I placed myUserControl.ascx?

Thanks,

Oct 5 '06 #3
SAL
I thought about that, but the developer who coded this originally did not do
that and uses ViewState, Session, Request all though out the Webpage making
exceptionally hard to do, considing I only have a short time to make this
change. If I had more time, no problem.

If I did this myself I would have used classes and put very little code in
my .aspx page, which is the right way to do things like you said.
"David Jessee" wrote:
when you think about it, your button can not access any of the page members.
You're writing page code that accesses the button.

Since your page code should not contain any logic at all, this might be a
sign that you need to break out some functionality into some seperate classes

"SAL" wrote:
Hello,

I created a WebPage.aspx that has some functions in it, and I created a User
Control that has a File Field Control and a Botton control on the .ascx. I
added myUserControl.ascx to the WebPage.aspx, but it can not access the
WebPage.aspx functions.

If I add a button to the WebPage.aspx, I can access those functions no
problem. Is not adding a User Control the samething? If not, what must I do
in myUserControl.ascx file so I can access the functions that are on the
WebPage.aspx where I placed myUserControl.ascx?

Thanks,
Oct 5 '06 #4
All you have to do is in your user control code use
(assume your class name for your aspx page is Webform1.cs
Webform1 form = this.Page as Webform1;

if(form ! == null)
{
// call the page function here
form1.funcation();
}

"SAL" <SA*@discussions.microsoft.comwrote in message
news:CA**********************************@microsof t.com...
>I thought about that, but the developer who coded this originally did not
do
that and uses ViewState, Session, Request all though out the Webpage
making
exceptionally hard to do, considing I only have a short time to make this
change. If I had more time, no problem.

If I did this myself I would have used classes and put very little code in
my .aspx page, which is the right way to do things like you said.
"David Jessee" wrote:
>when you think about it, your button can not access any of the page
members.
You're writing page code that accesses the button.

Since your page code should not contain any logic at all, this might be a
sign that you need to break out some functionality into some seperate
classes

"SAL" wrote:
Hello,

I created a WebPage.aspx that has some functions in it, and I created a
User
Control that has a File Field Control and a Botton control on the
.ascx. I
added myUserControl.ascx to the WebPage.aspx, but it can not access the
WebPage.aspx functions.

If I add a button to the WebPage.aspx, I can access those functions no
problem. Is not adding a User Control the samething? If not, what
must I do
in myUserControl.ascx file so I can access the functions that are on
the
WebPage.aspx where I placed myUserControl.ascx?

Thanks,

Oct 6 '06 #5

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

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
11
by: Lloyd Sheen | last post by:
Is there any one who has actually done this. I have now scanned more web articles about this with the realization that not one of them (including MSDN docs) outlines how to do this. This is...
5
by: Marcel Gelijk | last post by:
Hi, I am trying to create a User Control that is located in a seperate class library. The User Control contains a textbox and a button. The page generates an exception when it tries to access...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
2
by: Hans Merkl | last post by:
Hi, I am trying to use a user control as EditItemTemplate in a DataList. It loads fine but I can't figure out how to bind to the data of the DataList. Here is what I have got so far: ...
0
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file called A One project that build a user control dll. In this user control we have a class...
5
by: Guy Noir | last post by:
I have a quick question on custom controls. I have a control that I created with a class that extends the NumericUpDown control. My problem is that when I use this usercontrol on my form, the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.