I think you can do that , we will use Control.RenderControl() method to generate HTML output
here a code that makes things clear
// from your db
string html = @"<table style="" width:50%; background-color:lightGray;""><tr><td></td> <td>[txtID]</td></tr><tr><td></td><td>[txtName]</td></tr></table>";
//
TextBox txtID = new TextBox();
TextBox txtName = new TextBox();
StringBuilder sb = new StringBuilder();
StringWriter sr = new StringWriter(sb);
HtmlTextWriter tw = new HtmlTextWriter(sr);
txtID.RenderControl(tw);
string txtIDOutout = sb.ToString();
sb.Clear();
txtName.RenderControl(tw);
string txtNameOutout = sb.ToString();
html = html.Replace("[txtID]", txtIDOutout);
html = html.Replace("[txtName]", txtNameOutout);
Literal1.Text = html;
If I give you a useful answer, please click the ANSWER button. (Please do this for ALL posts that are really useful.)
kashifabbasi
Member
18 Points
13 Posts
Dynamic HTML Put on static controls
May 23, 2011 06:47 AM|LINK
Dear All,
i have a aspx web page contain two text boxes i.e
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
i have HTML in data base and i retrive it in cs file at any event(i.e int, preint or load).the html is like following
<table style=" width:50%; background-color:lightGray;">
<tr><td></td> <td>[txtID]</td></tr>
<tr><td></td><td>[txtName]</td></tr>
</table>
NOW i want to replace [txtID] with <asp:TextBox ID="txtID" runat="server"></asp:TextBox>
and [txtName] with <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
in simple word i want to change html of static controls.there is no single line of HTML on aspx page except controls
give ur ideas
Thanks
billel47
Member
711 Points
109 Posts
Re: Dynamic HTML Put on static controls
May 23, 2011 10:03 PM|LINK
Hi,
I think you can do that , we will use Control.RenderControl() method to generate HTML output
here a code that makes things clear
// from your db string html = @"<table style="" width:50%; background-color:lightGray;""><tr><td></td> <td>[txtID]</td></tr><tr><td></td><td>[txtName]</td></tr></table>"; // TextBox txtID = new TextBox(); TextBox txtName = new TextBox(); StringBuilder sb = new StringBuilder(); StringWriter sr = new StringWriter(sb); HtmlTextWriter tw = new HtmlTextWriter(sr); txtID.RenderControl(tw); string txtIDOutout = sb.ToString(); sb.Clear(); txtName.RenderControl(tw); string txtNameOutout = sb.ToString(); html = html.Replace("[txtID]", txtIDOutout); html = html.Replace("[txtName]", txtNameOutout); Literal1.Text = html;kashifabbasi
Member
18 Points
13 Posts
Re: Dynamic HTML Put on static controls
May 24, 2011 06:33 AM|LINK
thanks, through this how i can manage the event of any control.. supose i have a button control on aspx page
<asp:button id="btnOk" runat="server" Text="OK" Click="btn_Click" />
than how i can manage the click event of button
billel47
Member
711 Points
109 Posts
Re: Dynamic HTML Put on static controls
May 24, 2011 06:39 AM|LINK
Hi,
to handle events , you can create event handlers programmatically
for example :
btnOk.click =+ MyEventHandler; (the signature of MyEventHandler must be the same with event click).
or btnOk.click =+ new EventHandler(MyEventHandler); (EventHandler is a delegate).