PROKA Posted November 16, 2007 Posted November 16, 2007 Hello, I want to insert HTML Code inside a <div id="div1" I want to search for that div, by its ID It was something like element.innerhtml ...... forgot better if u give me a solution w\ Javascript Quote Development & Research Department @ Elven Soft
RedLeader Posted November 16, 2007 Posted November 16, 2007 Try this: <html> <head> <title>some title</title> <script type="text/jscript"> function setDivCode(myCode) { var myDiv = document.getElementById('div1'); myDiv.innerHTML += myCode; } </script> </head> <body> <input type="text" id="txt" value="<b>here is my code</b>"/> <input type="button" id="btn" onclick="setDivCode(txt.value);" /> <div id="div1"> <a href="http://www.google.com" id="lnk">google</a> </div> </body> </html> Quote
PROKA Posted November 17, 2007 Author Posted November 17, 2007 Ok, This is a start. But I'm kinda nubish with JavaScript. What I need is something to work with from asp.net, in the .vb code behinde file. That's because I work with sql and I have to insert in that div data from SQL. Quote Development & Research Department @ Elven Soft
PROKA Posted November 17, 2007 Author Posted November 17, 2007 OK I found out how and I'll post it here for others searching for the same thing: The trick is to put in the html code runat="server" for the div element: <div id="div1" runat="server"> </div> then in ASP.NET use div1.InnerHtml to insert Html. Now I wonder if there's a way to delete a div from the html. (not only to set its InnerHtml to nothing) Quote Development & Research Department @ Elven Soft
RedLeader Posted November 19, 2007 Posted November 19, 2007 So, if you add that div from Codebehind you'll have no problem to remove it. This example will show you how to add DIV to TableCell (You can add it to whatever you want ) and how to remove it. aspx code: .... <table> <tr> <td id="myTD" runat="server"> </td> </tr> </table> .... aspx.cs code: HtmlGenericControl div2 = new HtmlGenericControl("div");//DIV declaration protected void Page_Load(object sender, EventArgs e) { div2.ID = "div2"; HtmlButton btn = new HtmlButton(); //put some DIV controls just to see if it's there btn.ID = "btn1"; div2.Controls.Add(btn); myTD.Controls.Add(div2);// Add it to the TableCell } protected void Button1_Click(object sender, EventArgs e) { //Here is, remove the DIV. myTD.Controls.Remove(div2); } } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.