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!
************************************************** ********************
"ani" <> wrote in message
news:08ee01c39c99$7d8f0480$...
> 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!
|