Dynamic GUI in ASP.NET

M

MscrmGuy

Hi all:

I am trying to build a web interface for a CRM demo I am working on, and one
of the questions on the registration form is "How many children do you
have?" and then I want the user to be able to enter info for each child.

So I'd like the page to function such that if the user enters "4", the
interface updates and displays 4 input rows with textboxes for name, age,
etc. This seems to be hard to do in ASP.NET, does anyone think AJAX might be
an answer? Can anyone offer any other ideas as to how I might accomplish
this?

Thanks.
 
G

George Ter-Saakov

use Javascript. Create 15 textboxed with the name schema "child1",
"child2",..... and set the style="display:none"
then use Javascript to switch style to display:inline

Like
function siwtchOn(n)
{
var i;
for(i = 0; i < 15; i++ )
{
if( i < n )
document.getElementbyId('child1').style.display="inline";
else
document.getElementbyId('child1').style.display="none";
}
}
Then you would avoid postback

PS: You will need to pay attention to IDs ASP.NET might change them if your
input boxes are server controls.
So they will become someting like _parentId_child1, _parentId_child2....

George.
 
B

Bjorn Sagbakken

MscrmGuy said:
Hi all:

I am trying to build a web interface for a CRM demo I am working on, and
one
of the questions on the registration form is "How many children do you
have?" and then I want the user to be able to enter info for each child.

So I'd like the page to function such that if the user enters "4", the
interface updates and displays 4 input rows with textboxes for name, age,
etc. This seems to be hard to do in ASP.NET, does anyone think AJAX might
be
an answer? Can anyone offer any other ideas as to how I might accomplish
this?

You can add controls dynamically with ASP.NET. Using an asp:table you can
add your 4 rows, each containing the number of cells you want. Then you add
the type of controls you want; labels, texboxes, images and so on into each
cell. It is a good idea to use a loop-counter and give each control a unique
ID based on the rowID+controlname. Then you easily can retrieve the entered
values on postback.

One trick that challenged me was that the dynamically controls must be
created each time the page is posted back. The data entered into each
control are automatically stored into viewstate, but you have to design a
loop in the page load section to regrenerate the rows of controls. I'm sorry
I don't have any relevant links for the, but google for "adding controls
dynamically" and you will surely find a lot of info.

Bjorn
 
B

Brian Simmons

Bjorn's hit the nail on the head here, and he's right the trickiest part is
having to creating the controls on each postback even tho' the data is
stored in the ViewState.
I do this type of thing all the time and it works perfectly.

I would highly recommend: Creating a simple project/website completely
separate from whatever you're working, just to play around with the
concepts.
 
M

mike

As an alternative, you could have one data entry form and an Add
button and then below it have a GridView that displays the details
that have already been submitted. This may be a mroe flexible option
as you don't need to consider how to handle someone changing their
mind - such as remembering that they actually have a 5th child.

You won't need to remember to recreate any controls, only to execute
GridView.DataBind in your AddButton.Click method to refresh the
GridView.

Mike
 

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,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top