User Controls Passing Variables from one control to another

P

Philip Poole

Hello everyone,

Please help with this as it is driving me up the wall and it is urgent i
finish this page, this is the first time I have used User Controls and I
think I must have completly misunderstood a basic point.

I have a number of user controls which are used to make up my page. One
control is a series of tabs which are created dynamically from a database.
When someone clicks on a tab, the page reloads and the tabs that was clciked
changes colour to signify it has been selected.

The tabs to be displayed are decided by integer I set by a property.

After the tabs has been created i then want to generate the rest of my page
which wil be dependent on the id of the selected tab.

At the moment I have in my template file (which contains all of the user
controls) a page load method, in the page load method i call the functions
to generate my page. However, this functions are dependent on the selected
tab in the user control and the user control fuctions are not generated
until after the page load of my template page. i.e

Template.Page_Load() {

generatePage(id) //but no id!!!!

}

SideTabs.Page_Load()

Whereas what I would like is

Template.PageLoad() {
//some function calls

SideTabs.PageLoad()

int id = SideTabs.SelectedTabId

GenerateContent(id)
}

Is this possible? Or how can I get this type of functionaility.

Please help

Philip
 
J

Josh

Make your tab properties store thier data in the viewstate and have the
other controls access that.
 
P

Philip Poole

Hello Josh,

Thankyou kindly for the advice

do you have any idea on how I do that?

Phil
 
J

Jim Corey

This scenario looks very similar to the Time Tracker starter kit at
www.asp.net.

If SideTabs is a user control, then I don't think you want to explictly
call its page_load event. You just want to load the control, probably
by calling LoadControl.

The specific control has to be loaded with each postback.
Something that had me stumped for a long time is that you must also load
a value to the id property of the control each time (I typically use the
name of the control) and this helps the program keep everything in sync.

A different approach would be to have one base control class for all the
user controls, and put the functions there, but I don't know if that
will help anything in your situation.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top