Saving a code generated control to a string

  • Thread starter Thread starter Ryan Ternier
  • Start date Start date
R

Ryan Ternier

I have an HTML string that I am throwing into the InnerHTML property of a
server side div.

Is there a way that I can create an ASP.NET imagebutton, set the events,
ID's, names etc. and save that to an HTML string (back end) and then when
the string is sent out to the div, the new imagebutton would have full
functionality like a regular control?

I cannot use the asp:placeholder.

Any help would be very appreciated, thank you.
 
Ryan,

What stops you from adding a new ImageButton to Controls collection of the
Div server control?
 
Well... I could, but then I'd have to re-write the entire engine that prints
out this ordered list.

Currently it's being saved into our custom string object then printed into
the div...

The way you're presenting I would:.

Div.InnerHTML += "...."

and then when I need to add a control i add it via:
divTest.Controls.Add(....);

hmm, I'll give it a shot. Thanks for the help.

On a sidenote though... is it still possible to render a server control into
an HTML string and then output that string to the web form, which renderes
the server control? It would be useful.
 
So I changed the way I coded the Ordered list:

I created a function:
private Literal AddText(string Text)
{
Literal litHTML = new Literal();
litHTML.Text = Text;
return litHTML;
}


And instead of doing:

divAgenda.InnerHTML += "";

I changed it to:

divAgenda.Controls.Add(AddText(""));

which would allow me to add iamgebuttons.

THe reason I had to do this, is once you add controls to another container,
the InnerHTML property is useless because it is not literal anymore.

Thanks for pointing me in this direction.

/RT
 

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

Back
Top