I have an input type-text that is created dynamically via asp.net after a div is being clicked on:
divID.innerHtml = "<input type='text' runat='server' id='box' value='' />";
what i am trying to do is when the div is clicked again, to get the value of the textbox in asp.net.
the problem is – the textbox does not exist so the compiler gives me an error for trying to use its name.
Is there a way to do this?
i also thought that maybe there is a way to somehow use jquery to pass the value to asp.net.
Rather than create your textbox as
HTML, create the control and add it to your page.I.E
Using
ClientIDMode=Staticwill ensure the ID you set in the code-behind will be the one rendered to the HTML, rather than .net changing it.Then add this to your divID
You will now have access to it on postback by. In your postback method you will need to
FindControlto get the control – this is because its not a known control on your page. I am using FindControl on the divID, this will look inside that div for the textbox we created earlier.You will be also able to access this TextBox’s value via JQuery by calling
$("#box").val()should you need.