473,793 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User Control question

When I step through my code, the ASPX Page_Load happens before the Page_Load
in the User Control. This means that the property values are not set to
their defaults yet in the User Control and all the properties are blank. So
my question is, where is the best place to put the code that handles the
form. I was hoping to put it in the Page_Load on the ASPX page. Since the
properties aren't available to the ASPX page at that point, I have only a
few options that I can see.

1) Add all the Insert/Update code to the User Control, which I would rather
not do. I would like to keep the data manipulation out of the User Controls
so that I can use them other places. They are basically formatted forms
with exposed Properties. One problem with the separation idea is that the
Controls where I need to add events need to handled by the file that adds
the Control, unless I'm missing someway of wiring up events in the ASPX file
that happen in the User Control. Haven't seen a way to do that yet.
2) Use Request.Form to get the variables passed in the post. Although I've
found this to be problematic because sometimes the variable is prefixed with
'_ucl' or the User Control's name and a colon and sometimes it's not.
3) Add the manipulation code to and event that happens in the ASPX page.
For a form post I would add an event to the control I'm using for the submit
button.

Anyone care to comment? Give me some new ideas maybe?

Thanks in advance!
Andrea
Nov 18 '05 #1
6 1467
you should implement IPostBackDataHa ndler, so that your user control will be
updated with postback data before the onload event.

-- bruce (sqlwork.com)
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message
news:u0******** ******@TK2MSFTN GP11.phx.gbl...
When I step through my code, the ASPX Page_Load happens before the Page_Load in the User Control. This means that the property values are not set to
their defaults yet in the User Control and all the properties are blank. So my question is, where is the best place to put the code that handles the
form. I was hoping to put it in the Page_Load on the ASPX page. Since the properties aren't available to the ASPX page at that point, I have only a
few options that I can see.

1) Add all the Insert/Update code to the User Control, which I would rather not do. I would like to keep the data manipulation out of the User Controls so that I can use them other places. They are basically formatted forms
with exposed Properties. One problem with the separation idea is that the
Controls where I need to add events need to handled by the file that adds
the Control, unless I'm missing someway of wiring up events in the ASPX file that happen in the User Control. Haven't seen a way to do that yet.
2) Use Request.Form to get the variables passed in the post. Although I've found this to be problematic because sometimes the variable is prefixed with '_ucl' or the User Control's name and a colon and sometimes it's not.
3) Add the manipulation code to and event that happens in the ASPX page.
For a form post I would add an event to the control I'm using for the submit button.

Anyone care to comment? Give me some new ideas maybe?

Thanks in advance!
Andrea

Nov 18 '05 #2
I've looked around on the web sites (that I know about) that offer samples
and found pretty cryptic information on this subject. Interfaces are pretty
new to me and I'm not sure that they have been properly explianed to me. (I
moved from Classic ASP.) Are there any code samples that might help me
understand this a little more? I see the basics but I'm not sure what to do
in the overridden methods.

In the LoadPostData method, for example. Do I need to do something to make
the values be populated in the Controls?

Do I have to add the Render method and render my controls with code, or can
I just leave it in the HTML?

I just need a basic example that take a couple of HTML declared controls and
exposes them so that I can access the values in the ASPX Page_Load method.
All the samples I've seen are for another purpose.

Thanks!
Andrea
"bruce barker" <no***********@ safeco.com> wrote in message
news:uv******** *****@TK2MSFTNG P11.phx.gbl...
you should implement IPostBackDataHa ndler, so that your user control will be updated with postback data before the onload event.

-- bruce (sqlwork.com)
"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message
news:u0******** ******@TK2MSFTN GP11.phx.gbl...
When I step through my code, the ASPX Page_Load happens before the

Page_Load
in the User Control. This means that the property values are not set to
their defaults yet in the User Control and all the properties are blank.

So
my question is, where is the best place to put the code that handles the
form. I was hoping to put it in the Page_Load on the ASPX page. Since

the
properties aren't available to the ASPX page at that point, I have only a few options that I can see.

1) Add all the Insert/Update code to the User Control, which I would

rather
not do. I would like to keep the data manipulation out of the User

Controls
so that I can use them other places. They are basically formatted forms
with exposed Properties. One problem with the separation idea is that the Controls where I need to add events need to handled by the file that adds the Control, unless I'm missing someway of wiring up events in the ASPX

file
that happen in the User Control. Haven't seen a way to do that yet.
2) Use Request.Form to get the variables passed in the post. Although

I've
found this to be problematic because sometimes the variable is prefixed

with
'_ucl' or the User Control's name and a colon and sometimes it's not.
3) Add the manipulation code to and event that happens in the ASPX page.
For a form post I would add an event to the control I'm using for the

submit
button.

Anyone care to comment? Give me some new ideas maybe?

Thanks in advance!
Andrea


Nov 18 '05 #3
Andrea,

There's a few ways to set properties or call functions on the main page
from a user control. I'm using code like:

Dim myParent As MainReport

'The page is the HTTPHandler
myParent = CType(HttpConte xt.Current.Hand ler, MainReport)
myParent.myProp erty = "T"
myParent.myFunc tion()
where MainReport.aspx is the page.

I have one page and I load one of many controls at a time
and this is working well for me.

HTH,
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4
Set properties, yes. But if my property for a textbox in the User Control
looks like this:

public string Login
{
get{return txtLogin.Text;}
set{txtLogin.Te xt = value;}
}

And I try to get a value out of it from the ASPX Page_Load method, the value
is blank. This is b/c by default the Page_Load of the ASPX loads before the
UserControl loads, or at least that's what I'm assuming Since when stepping
through the code I get all the way through Page_Load for the ASPX and then
it pop over to the Page_Load in the User Control, where at that point, I can
see that now the Properties return values.

So if what you propose would fix my problem and allow me to access the
properties from the User Control in the Page_Load method of the ASPX page,
I'm not seeing it. Can you explain a little more?

Thanks!
Andrea
"Jim Corey" <jc****@nospamc harter.net> wrote in message
news:uX******** *****@TK2MSFTNG P09.phx.gbl...
Andrea,

There's a few ways to set properties or call functions on the main page
from a user control. I'm using code like:

Dim myParent As MainReport

'The page is the HTTPHandler
myParent = CType(HttpConte xt.Current.Hand ler, MainReport)
myParent.myProp erty = "T"
myParent.myFunc tion()
where MainReport.aspx is the page.

I have one page and I load one of many controls at a time
and this is working well for me.

HTH,
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5
No, my example would not help in the way you describe.
If you were reacting to a button on the user control you would be ok, since
the value would be there by the time the button_click event got fired (
after the page_load events for
the page and user control.

Plus I don't know if you're property is going to work, since there would
have to
be some way to persist 'value' across postbacks.

You may want to check some of the sample apps at www.asp.net / starter kits.
The time tracker app uses user controls and you may see a pattern that fits
what you're trying to do.

Jim

"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message
news:#y******** ******@TK2MSFTN GP10.phx.gbl...
Set properties, yes. But if my property for a textbox in the User Control
looks like this:

public string Login
{
get{return txtLogin.Text;}
set{txtLogin.Te xt = value;}
}

And I try to get a value out of it from the ASPX Page_Load method, the value is blank. This is b/c by default the Page_Load of the ASPX loads before the UserControl loads, or at least that's what I'm assuming Since when stepping through the code I get all the way through Page_Load for the ASPX and then
it pop over to the Page_Load in the User Control, where at that point, I can see that now the Properties return values.

So if what you propose would fix my problem and allow me to access the
properties from the User Control in the Page_Load method of the ASPX page,
I'm not seeing it. Can you explain a little more?

Thanks!
Andrea
"Jim Corey" <jc****@nospamc harter.net> wrote in message
news:uX******** *****@TK2MSFTNG P09.phx.gbl...
Andrea,

There's a few ways to set properties or call functions on the main page
from a user control. I'm using code like:

Dim myParent As MainReport

'The page is the HTTPHandler
myParent = CType(HttpConte xt.Current.Hand ler, MainReport)
myParent.myProp erty = "T"
myParent.myFunc tion()
where MainReport.aspx is the page.

I have one page and I load one of many controls at a time
and this is working well for me.

HTH,
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #6
I have, actually, that's why I think that I should be able to do it this
way.

For an example, look at this URL:

http://www.dotnetjunkies.com/quickst...s/Pagelet5.src

When you see the source of the User Control, they are exposing the
properties as I would like to.

Later....

I just made a few modification and ran the debugger again... I don't know
why I wasn't seeing the values populated, but I am now. I'm very confused.
Maybe a caching issue the last time I ran it? Guessing...

I could go back to a previous version to see, but I'm so happy that it's
working that I don't want to spend any more time on it. If I run into
again, I'll pull back my old version and see if I can find where the problem
was.

I still would like to react to events from the User Control in my ASPX page
and would like some batter instructions and samples on that subject, should
anyone have something.

Thanks again!
Andrea
"Jim Corey" <jc****@nospam. charter.net> wrote in message
news:10******** *****@corp.supe rnews.com...
No, my example would not help in the way you describe.
If you were reacting to a button on the user control you would be ok, since the value would be there by the time the button_click event got fired (
after the page_load events for
the page and user control.

Plus I don't know if you're property is going to work, since there would
have to
be some way to persist 'value' across postbacks.

You may want to check some of the sample apps at www.asp.net / starter kits. The time tracker app uses user controls and you may see a pattern that fits what you're trying to do.

Jim

"Andrea Williams" <an*******@hotm ail.IHATESpam.c om> wrote in message
news:#y******** ******@TK2MSFTN GP10.phx.gbl...
Set properties, yes. But if my property for a textbox in the User Control looks like this:

public string Login
{
get{return txtLogin.Text;}
set{txtLogin.Te xt = value;}
}

And I try to get a value out of it from the ASPX Page_Load method, the

value
is blank. This is b/c by default the Page_Load of the ASPX loads before

the
UserControl loads, or at least that's what I'm assuming Since when

stepping
through the code I get all the way through Page_Load for the ASPX and then it pop over to the Page_Load in the User Control, where at that point, I

can
see that now the Properties return values.

So if what you propose would fix my problem and allow me to access the
properties from the User Control in the Page_Load method of the ASPX page, I'm not seeing it. Can you explain a little more?

Thanks!
Andrea
"Jim Corey" <jc****@nospamc harter.net> wrote in message
news:uX******** *****@TK2MSFTNG P09.phx.gbl...
Andrea,

There's a few ways to set properties or call functions on the main page from a user control. I'm using code like:

Dim myParent As MainReport

'The page is the HTTPHandler
myParent = CType(HttpConte xt.Current.Hand ler, MainReport)
myParent.myProp erty = "T"
myParent.myFunc tion()
where MainReport.aspx is the page.

I have one page and I load one of many controls at a time
and this is working well for me.

HTH,
Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Nov 18 '05 #7

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

Similar topics

11
1686
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 beyond frustration. It seems that with every new VS release the documentation falls further behind. What I want to do should be simple but I can find no way to do it with VS with any visual designer support. I thought the 'V' in VS stood for...
6
402
by: Jim Heavey | last post by:
Hello, I have a user control which I place at the top of each page. I want to have code in this user control which sets the value of a couple of module variables and I was wondering if I create a Variable name of "Public string Fred" in the control, will the page that uses the control be able to see this global variable or is there something that I need to do to make it available to the page which uses the control Thanks in advance for your...
1
1022
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a variable (targetId) in to the usercontrol (IntergySite.aspx) by calling its setter method. Currently, I am using if-then-else and hardcoded the User Control Object to do casting and call the setter method. Question: Is there any way I could load,...
8
1501
by: Prince Mathew | last post by:
Hi All, I have a requirement. I am throwing an exception from my user control I want to catch this in my container page. Is this possible? I don't want any event to be raised. PLEASE HELP ME.
0
1173
by: campwes | last post by:
Hey there. I have a user control on an aspx page that displays data based on a query (handled by another user control also on the page). I've noticed that the first time I navigate to the page with the user control, I can click on links, buttons etc on the user control and navigate around. On subsequent postbacks, say when a user submits a new query, the buttons and links on the user control are "un-clickable". You get no click sound...
0
1159
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind page of the 'main' web page. I have done this so far...
0
978
by: Brian Cesafsky | last post by:
I am using framework 1.1 I have a user control and a web page. I want to set up properties on the user control, so I can access the text boxes on the user control when I am in the code behind page of the 'main' web page. I have done this so far...
1
1822
by: weboweb | last post by:
Hello aspnet experts! I have a design question for the more experienced developers (more than me at least :-)). 1) I have a page in the application I'm building that displays a web user control with a list of folders (let's call it the TREE) 2) There is another control called document list which shows the list of documents for the selected tree folder (let's call it DOCLIST)
9
3194
by: Gummy | last post by:
Hello, I created a user control that has a ListBox and a RadioButtonList (and other stuff). The idea is that I put the user control on the ASPX page multiple times and each user control will load with different data (locations, departments, etc.).
4
2493
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried unsuccessfully in creating the whole pane as a user control and have succeeded in adding the pane and then dynamically adding the content which is a user control to the pane, dynamically within the page. However I would like to have a single pane...
0
9671
marktang
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...
0
10433
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, 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...
0
10212
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10161
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,...
0
10000
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6777
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();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2919
bsmnconsultancy
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...

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.