Hossain Ehsani
Hossain Ehsani

Reputation: 395

adding text box to span not working

I'm trying to add a text box to my web page using span and I use this snippet but it`s not working. Can someone please help me?

answerResualts.InnerHtml += "<table>";
    answerResualts.InnerHtml += "<tr>";
    answerResualts.InnerHtml += "<td>";
    answerResualts.InnerHtml += @"<asp:TextBox ID=""TextBox1"" runat=""server"" TextMode=""MultiLine"" Text=""test""></asp:TextBox>";
    answerResualts.InnerHtml += "</td>";
    answerResualts.InnerHtml += "</tr>";
    answerResualts.InnerHtml += "</table>";

Upvotes: 0

Views: 82

Answers (2)

Eskir
Eskir

Reputation: 784

If you're building parts of your web page in JS, why not just use DOM and it's functions straight away?

var element = document.createElement("TABLE");
var tableRow = document.createElement("TR"); 

etc.

This has the added benefit of being able to use DOM to make changes or add things, and you can loop the whole thing to dynamically create your tables if you'd ever need to.

With jquery, it should be relatively easy to add stuff as well, as you get functions like AppendNode, append, prepend, etc.

Besides:

Please reconsider using a <span> tag for things other than text, that's not what it is meant for.

Upvotes: 1

G&#252;ven Altuntaş
G&#252;ven Altuntaş

Reputation: 253

First, javascript properties are case sensitive. Use innerHTML to change html.

Second, I believe that you are using asp web forms, but you should use html tags in javascript or render your html as text before putting it in js.

Upvotes: 0

Related Questions