create dynamic control in mvc4 razor
i need to create dynamically a textbox with header text when i click add link
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
vidhyaPosted Jul 24, 2013, 5:19 AM
Did u see my screen which i sent before.
when i click add ,i should add the statement and response text box and label. be stable in the page itself.
Sunny SharmaPosted Jul 24, 2013, 5:13 AM
Obviously, this is why it's dynamic. otherwise you could have set the desired layout in view itself. Contents added dynamically will be reset always. I'm not getting your point on requirements. My Answers satisfies your question. You can ask for more if otherwise needed. Elaborate on what you want to do.
vidhyaPosted Jul 24, 2013, 5:06 AM
Sunny SharmaPosted Jul 24, 2013, 5:00 AM
use this script:
--------------------------------
<script src="~/Scripts/jquery-1.8.2.min.js">script>
<script type="text/javascript">
var textBoxCount = 0;
$(document).ready(function () {
$("#txt").click(function () {
textBoxCount++;
var lbl = $(' + textBoxCount + '').attr({ for: 'text' + textBoxCount });;
var $ctrl = $('').attr({ type: 'text', id: 'text'+textBoxCount, value: 'text' }).addClass("text");
$("#holder").append(lbl);
$("#holder").append($ctrl);
});
});
script>
@using (Html.BeginForm()) {
<div>
<fieldset>
<legend> <span>2.span> Statements & Responseslegend>
<input type="button" id="txt" value="Add TextBox" style="" />
<div id="holder"> div>
fieldset>
div>
}
-----------------------------------------------------------------
It will Work.
Mark it as answer if it helps. Cheers!
vidhyaPosted Jul 24, 2013, 4:27 AM
var totpts = 0;
var bol = 0;
}
@using (Html.BeginForm())
{
}
I have a code which works fine, but i need to display the number before the text box how can i display it.
eg: text1 textbox here
text2 textbox here
text3 texxtbox here
At every click i need to increment the number.
vidhyaPosted Jul 24, 2013, 4:06 AM
When i used like this i am getting this error.
Iftikar HussainPosted Jul 24, 2013, 1:09 AM
Please refer the below link
http://techbrij.com/add-dynamic-form-elements-textbox-button-radio-checkbox
http://forums.asp.net/t/1763533.aspx/1
Regards,
Iftikar
Sunny SharmaPosted Jul 24, 2013, 1:09 AM
Please don't share only the screen, I'll have to write the whole code for you then. Share the code that you have so far towards the problem and I'll do the modifications for you. It will same my time as well as yours also. Hope you got my point.
vidhyaPosted Jul 23, 2013, 11:55 PM
i have attached the file for your reference. this was my scenario.
When i click add link, it should add the text box.
Sunny SharmaPosted Jul 23, 2013, 8:15 AM
You can do this with jQuery. Follow the pattern below:
$('div.content').append("")
"div.content" is the selector of parent element where you want to append textbox.
Hope it helps.
Cheers!