0

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

2 Answers 2

2

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!

Sign up to request clarification or add additional context in comments.

1 Comment

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" />
0

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.