views:

47

answers:

2

Hi All,

I want to create a textbox on the fly (in the comment section im creating). Now I would like your opinion on whats the best solution. I was thinking about using a webmethod and add a textbox control dynamically, but since this requires a call to the server I'm not sure if that's the best option. Or can i also spawn a textbox using plain old javascript and still getting it's value on postback?

Thanks again guys

Kind regards, Mark

A: 

You can create a new element using plain old JavaScript:

var textbox = document.createElement("textarea");
textbox.className = "my-textarea"; //Styling with CSS 
document.getElementById("myelement").appendChild(textbox);
floatless
+1  A: 

Put the TextBox using ordinary HTML input element on page and set its visibility property to collapsed using style tag then in code behind make it visible.

HTML Tag:

<input id="myTextBox" type="text" style="visibility: collapse;" />

Javascript:

var txt = document.getElementById("myTextBox");
txt.style.visibility = "visible";

Hope this helps!

Umair Ashraf
if you want to access the textbox from server side also add a attribute in the HTML tag as follows:<input id="myTextBox" type="text" style="visibility: collapse;" runat="server" />
Umair Ashraf