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

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 1443
you should implement IPostBackDataHandler, so that your user control will be
updated with postback data before the onload event.

-- bruce (sqlwork.com)
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:u0**************@TK2MSFTNGP11.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*************@TK2MSFTNGP11.phx.gbl...
you should implement IPostBackDataHandler, so that your user control will be updated with postback data before the onload event.

-- bruce (sqlwork.com)
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:u0**************@TK2MSFTNGP11.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(HttpContext.Current.Handler, MainReport)
myParent.myProperty = "T"
myParent.myFunction()
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.Text = 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****@nospamcharter.net> wrote in message
news:uX*************@TK2MSFTNGP09.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(HttpContext.Current.Handler, MainReport)
myParent.myProperty = "T"
myParent.myFunction()
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*******@hotmail.IHATESpam.com> wrote in message
news:#y**************@TK2MSFTNGP10.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.Text = 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****@nospamcharter.net> wrote in message
news:uX*************@TK2MSFTNGP09.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(HttpContext.Current.Handler, MainReport)
myParent.myProperty = "T"
myParent.myFunction()
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.supernews.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*******@hotmail.IHATESpam.com> wrote in message
news:#y**************@TK2MSFTNGP10.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.Text = 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****@nospamcharter.net> wrote in message
news:uX*************@TK2MSFTNGP09.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(HttpContext.Current.Handler, MainReport)
myParent.myProperty = "T"
myParent.myFunction()
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
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...
6
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...
1
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...
8
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...
0
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...
0
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...
0
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...
1
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...
9
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...
4
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...
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:
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: 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
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:
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...
0
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,...
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
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...

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.