Getting data to a user control?

  • Thread starter Thread starter news.microsoft.com
  • Start date Start date
N

news.microsoft.com

Hi,

Files related:
1. Search.aspx <- contains a <mycontrol:simplepaging runat=server>
2. Search.aspx.cs <- codebehind
3. SimplePaging.cs

How do I send data from the codebehind into the user control and visa versa?

Thanks a lot for any reply.
Anders
 
Okay, now think about ASP.Net as an object-oriented technology, and the
answer should become obvious. You don't want to send data from one FILE to
another. You want to send data from one OBJECT to another. Now, how do you
do that? You either expose a property or a method that can accept data in
one class, and pass it from the other via that interface.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Yes I could make a property value in simplepaging called MyDataTable but
still how do I fill it?

I though of doing a Control simplePaging = Page.FindControl("SimplePaging");
but how do I fill it with the datatable?

Thanks
 
Once you have a handle on the Control, just cast it as the type it is, and
reference the property.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Thanks Kevin, you give us food for thought :)

I was planning to have the simplepaging.cs return the DataTable to the
codebehind file so that it can databind it. But is that good programming?

cheers,
Anders
 
Hi Anders,

I can't answer that question. I don't know enough about your app to be able
to.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Thanks for all the help so far Kevin. Im beginning to understand the OOP.

I am overriding the OnInit event to do the Page.LoadControl of the ascx
file. Is that an appropriate way?

I am inheriting WebControl.

best,
Anders

"Kevin Spencer" <[email protected]> wrote in message news:%23
 
Hi Anders,

It may or may not be appropriate, depending on the circumstances. If it is
working, I would suspect that it's okay. You can read all about the Control
Execution LifeCycle at:

http://msdn.microsoft.com/library/d...guide/html/cpconControlExecutionLifecycle.asp

This reference is applicable to ALL Server Controls, including
System.Web.UI.Page, and is quite handy when deciding when to perform certain
types of operations.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Back
Top