Question:
How we get The Value of Dynamic generate TextBox in asp.net?
aekta
2007-03-31 02:38:07 UTC
How we get The Value of Dynamic generate TextBox in asp.net? i have a web form and in which i want to create textbox dynamically by click on Button.Now on another button click,I want to get value entered in textbox.
Five answers:
Smutty
2007-03-31 08:13:52 UTC
when creating the textbox assign it an ID so that you can reference it later just like a textbox generated at design time.



Here it how it goes:

<%@ Page Language="C#" %>









Untitled Page














 











Alex Turner
2007-03-31 02:50:20 UTC
This is not really an ASP.net question. It is a DHTML question. There are a couple of solutions. Maybe the easiest its to dynamically create an entire form in which there is a textbox (textarea?) and a submit button. You handle submit of the form in the normal way. You can create such a form by creating the html in JavaScript and setting the innerHTML property of a DIV to the HTML.



An alternative is to give the dynamically generated textbox an ID. When the button to submit is hit, it has an 'onclick' listener which runs a JavaScript function. That function gets a reference to the textbox via the 'document.getElementById('') method. It then looks up the contents of the box via the 'value' property of the object. You can do anything you want with that value then, including submitting it with AJAX.



It is the latter method that my application 'InstaChat' (http://www.nerds-central.com/InstaChat') uses.



There is a shed load of information on DHTML and AJAX on nerds-central :) pop into http://www.nerds-central.com or join our email discussion list.



Best Wishes - AJ
And now I am a Mom
2007-03-31 08:08:43 UTC
1)You can place as many as textboxes needed at design time can hide the unwanted textboxes at required places.



(or)



2)you can use Load statement as in VB, and create an array of that control(textbox) and can refer to the subscrpit of that control.



Like



dim textbox1 as new textbox

on button_click

{

load new textbox

}



or



while(j
{

load textbox1[j]

j++

}



Hope i too participated to clear your doubt!!!
anonymous
2007-03-31 03:59:23 UTC
One thing you might want to do is create the text box hidden (by setting Visible property to false). Then when you press the first button, show the text box:



textbox.Visible=true;



It will give the same effect as if the box was created dynamically.



Then, when you press the second button, you can get the text like this:



string text=textbox.Text;



For more tips, visit http://www.mycsharpcorner.com



Hope this helps,
Carmen
2016-03-17 09:31:18 UTC
People are telling you complex answers to something so simple... this will do the trick for you. document . getElementById('Txt') . value That will give you the text in the input. Remove the spaces, I had to put them in for it to display properly.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...