Groups | Blog | Home
all groups > asp.net webcontrols > december 2005 >

asp.net webcontrols : Referencing controls inside Wizard control


James Bond
12/29/2005 4:20:02 PM
Hi all,

I am having trouble referencing (directly) the controls (web) inside the
wizard control.

I have a templated Header control wherein I have a asp:Label. Eventhough
the IDE shows the control in Server Objects, I am unable to reference in my
Brock Allen
12/30/2005 8:38:20 AM
Use:

TextBox textBox1 = WizardStep1.CustomNavigationTemplateContainer.FindControl("TextBox1")
as TextBox;

-Brock
DevelopMentor
http://staff.develop.com/ballen

[quoted text, click to view]

clintonG
12/30/2005 5:59:03 PM
Have you tried the late bound FindControl method?

Label lbl = (Label)(WizardName.FindControl("LabelName"));
lbl.Text = "Whatever";

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/



[quoted text, click to view]

Brock Allen
12/31/2005 9:22:37 AM
Unfortunately that doesn't work, Clinton, because of the template nature
of the wizard. It's necessary to go to the template container for whichever
step they need to get at:

For the content part it's:
_WizStep1.ContentTemplateContainer.FindControl

For the custom navigation part it's:
_WizStep1.CustomNavigationTemplateContainer.FindControl

-Brock
DevelopMentor
http://staff.develop.com/ballen

[quoted text, click to view]

clintonG
12/31/2005 12:24:21 PM
Of course, thank you for bringing this to our attention Brock.
I forgot the correct grammar even though I had to use "template containers"
in my grammar when learning to reference controls in the MasterPage.

Basically, as I am beginning to understand the 2.0 control tree, every
nested element of an HTML template becomes a control in the control tree
hierarchy. When referencing a "standard" control which may be located within
a template container -- a label or textbox for example -- we must use dotted
notation and a grammatical reference to each "template container" to
recreate the control tree hierarchy linearly. It would be great if we had a
"term" to refer to this grammatical process.

And if I'm not mistaken I don't think your reminder to use correct grammar
obviates the need for a cast. That would be correct ainna?

What I would like to master is when to decide to use public properties for
early bound references as I have this assumption that the use of public
properties allows standard controls which may be located within a template
container to be referenced directly.

This will be important for my own first use of the Wizard control which I am
just today finishing the HTML for and will need to access controls such as
CheckBoxList controls and so on. If public properties would make this
cleaner, more efficient and easier to code I'm all ears.

<%= Clinton Gallagher


[quoted text, click to view]

Simone Busoli
3/2/2006 7:29:06 AM
Try with this method, which gets a reference to an arbitrary control placed
at an arbitrary level in the Page hierarchy by its ID (call it by passing a
reference to your Wizard control's ControlCollection property)

public static Control FindControl(string controlID, ControlCollection
controls)
{
foreach (Control control in controls)
{
if(control.ID == controlID)
return control;

if(control.HasControls())
{
Control nestedControl = FindControl(controlID, control.Controls);

if(nestedControl != null)
return nestedControl;
}
}
return null;
}



--
Simone Busoli


[quoted text, click to view]
Bob C.
3/14/2006 9:02:15 AM
I'm wondering how to get a reference to the Next / Prior buttons so that I
can duplicate them in my button controls. When I click my Next button, I
want to fire the Wizard's next...

[quoted text, click to view]
AddThis Social Bookmark Button