Dynamic user control loading/initialising

J

Jo Inferis

Disclaimer : I'm fairly new to .NET (about 4 weeks and counting now...)

I have a page which contains multiple user controls, some of which it has
access to the methods of (by making the controls inherit from a generic
pre-compiled class). I want the containing page to read the value returned
by one of the control methods and depending on the value, either show or
hide a different control.

I initially tried to put this check in the Page_Load event handler, but at
this point it seemed that an asp control (a DropDownList) within the sub
control hadn't been initialised and so something as simple as the
SelectedValue wasn't yet available to the containing page (only on the first
load I found the page would always throw a System.FormatException since I
was trying to pass the value to int.Parse() )

I've now put the check in an overrided Render function which just notes the
value and then sets Visible on the sub control to either true or false
before calling base.Render

I'm aware that this doesn't seem like an elegant solution to the problem, so
I'd appreciate any advice there (particularly if I've just circumvented what
is actually a greater problem - my understanding of the ASP.NET
architecture)

I'm also aware that merely setting Visible = true or false on a control
doesn't actually stop most of the processing going on to set it up. I'd much
prefer to stop the control ever getting initialised but I'm not entirely
sure where to start looking for the techniques to do this....

thanks in advance,
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top