asp

A

ani

I need to dynamically load all the controls on to a page.
Most of the controls are either radio buttons or
checkboxes and the web page basically is a questionaire. I
am concatenating all the radio button items in a function
in my class. The function returns the concatenated text(in
the form of string) to the UI page . I am using asp
controls like <asp:radiobuttonlist> while concatenating.
The text is being displayed but not the radio buttons.
Can't I concatenate the asp server controls and return
them as a string ? Why is it the radio buttons are not
being displayed. Please help!
 
C

Cowboy \(Gregory A. Beamer\)

It is likely you are outputting a string that states your intent, but not
the actual controls. The reason is you are outputting client side script for
a server side control. As HTTP is stateless, you are sending garbage text to
the client, which does not understand, as it is intended for server side.

To dynamically add controls, use CodeBehind and some form of Container.
While the Page is a container, it is better to use something like a panel
or table. You can place text, either as a label, or as inner HTML in a table
cell, and you can attach controls. For the panel, it is as simple as:

myPanel.Controls.Add(myDynamicControl);

With a panel, you have to add them in order. For layout, tables are often a
better choice.

When you load the controls, you can bind the "choices" from a database table
to set up your radio buttons, et al.

Quick example (off the cuff, so you may need to alter to have it work):

Label lbl = new Label();
lbl.Text = "Choose a state<br>";

RadioButtonList rbl = new RadioButtonList();
rbl.DataSource = GetDataSetForStates();
rbl.DataBind();

pnlOutput.Controls.Add(lbl);
pnlOutput.Controls.Add(rbl);


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

**********************************************************************
Think Outside the Box!
**********************************************************************
 
E

Esteban Felipe

They are not being displayed because they haven't being
processed... Trying creating the controls and adding them
in a container like "Page":
CheckBox myCheckBox = new CheckBox();
myCheckBox.Text = "xxx";
Page.Controls.Add(myCheckBox);

Page, DataGrid, Table, PlaceHolders, etc.. are all
containers.
 

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,786
Messages
2,569,625
Members
45,320
Latest member
icelord

Latest Threads

Top