logo
down
shadow

Retrieve values from dynamically created textbox on knockout + MVVM


Retrieve values from dynamically created textbox on knockout + MVVM

By : user2952620
Date : November 19 2020, 01:01 AM
seems to work fine There are probably a few different problems:
You need to check out how constructor functions work. The KO docs have some info on related subjects, as does Stack Overflow. If you want to reference ViewModel from inside a function called on such a ViewModel you could use for example the below pattern. You expect abc to have a function called textValue, but that's after you have gone to-and-from JSON. JSON will not preserve functions like that. Your course view model does not expose textValue externally. You need to export it, e.g. using the self idiom. See example below. You have to change cources to cources(): it's an observableArray and to retrieve it's value you need to execute the observable.
code :
var CourseViewModel = function() {
  var self = this;
  self.textValue = ko.observable('initial value');
};

var ViewModel = function() {
    var self = this;
    self.cources = ko.observableArray([new CourseViewModel()]);
    self.retrieve = function() {
        var abc = ko.toJSON({ textValue: self.cources() }); 
        alert(abc);
    }
};

ko.applyBindings(new ViewModel());
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<div data-bind="foreach: cources">
  <input type="text" data-bind="value: textValue"/>
</div>
<input type="button" data-bind="click:retrieve" value="Value"/>
var CourseViewModel = function() {
  var self = this;
  self.textValue = ko.observable('initial value');
};

var viewModel = {
    cources: ko.observableArray([new CourseViewModel()])
};

viewModel.retrieve = function() {
    var abc = ko.toJSON({ textValue: viewModel.cources() }); 
    alert(abc);
};

ko.applyBindings(viewModel);
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<div data-bind="foreach: cources">
  <input type="text" data-bind="value: textValue"/>
</div>
<input type="button" data-bind="click:retrieve" value="Value"/>


Share : facebook icon twitter icon
dynamically retrieve textbox values using foreach jquery which itself is dynamically created

dynamically retrieve textbox values using foreach jquery which itself is dynamically created


By : Fledgling
Date : March 29 2020, 07:55 AM
Any of those help How to dynamically retrieve values from input text box : , You're missing a $ sign. It should be:
code :
$(":text").each(function(){
    alert($(this).val());
});
$('<td id="'+cId+'" width="'+cWidth+'">'+cName+'</td>').appendTo('#page-wrap');
$('<label for="'+cName+'">'+cName+'<input type="text" name="'+cName+'" id="'
    +cName+'" value="" class="text ui-widget-content ui-corner-all" /></label>')
    .appendTo('#moreItems');
How to retrieve the text of a dynamically created textbox and display its as a content of dynamically created button in

How to retrieve the text of a dynamically created textbox and display its as a content of dynamically created button in


By : hairexa
Date : March 29 2020, 07:55 AM
To fix this issue You may get the named TextBox by means of the FindName method:
code :
private void click(object sender, RoutedEventArgs e)
{
    var button = sender as Button;
    var parent = button.Parent as FrameworkElement;
    var textBox = parent.FindName("textbox1") as TextBox;
    button.Content = textBox.Text;
}
Retrieve the values from textbox which is dynamically created using C#

Retrieve the values from textbox which is dynamically created using C#


By : M Miyazaki
Date : March 29 2020, 07:55 AM
I hope this helps . I've had the same problem in the past.
What I did was give the dynamically-added control an ID, and made sure it retained that ID also on postback.
code :
protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
            this.NumberOfControls = 0; //very first time when page is loaded, value will be 0
        else
            this.createControls(); //if it is postback it will recreate the controls according to number of control has been created
    }

    //this is the base of this, it will hold the number of controls has been created, called properties
    protected int NumberOfControls 
    {
        get { return (int)ViewState["NumControls"]; }
        set { ViewState["NumControls"] = value; }
    }

    //it will create the controls 
    protected void createControls()
    {
        int count = this.NumberOfControls;
        for (int i = 0; i < count; i++) //loop for the total number of control.
        {
            TextBox tx = new TextBox(); //creating new control
            tx.ID = "ControlID_" + i.ToString(); //in your solution you are giving static id, don't do that, assign id number dynamically, it will help you further, if you want to manipulate the controls for some other use
            //Add the Controls to the container of your choice
            form1.Controls.Add(tx);
        }
    }

    //add new control
    protected void addSomeControl()
    {
        TextBox tx = new TextBox();
        tx.ID = "ControlID_" + NumberOfControls.ToString();
        form1.Controls.Add(tx);
        this.NumberOfControls++; //increment the number of control
    }

    protected void AddBtn_Click(object sender, EventArgs e)
    {
        addSomeControl(); 
    }
how to retrieve the value from a dynamically created textbox using its ID in asp.net?

how to retrieve the value from a dynamically created textbox using its ID in asp.net?


By : Suluh Arwani
Date : March 29 2020, 07:55 AM
may help you . Dim str As String=DirectCast(Page.FindControl("txtName"+i), TextBox).Text
it will not be accessable outside your loop, you will have to manage that with your code.
Is there a way to get the values of Dynamically created Textbox inside a Dynamically created GridView? Asp.net

Is there a way to get the values of Dynamically created Textbox inside a Dynamically created GridView? Asp.net


By : 建裔康
Date : March 29 2020, 07:55 AM
Hope this helps To find any Dynamic controls you have to use FindControl. This also works for GridView controls.
code :
//loop the dynamic gridviews
for (i = 1; i <= parCounter; i++)
{
    //use findcontrol and cast back to a gridview
    GridView gv = Panel1.ContentTemplateContainer.FindControl("GV" + i);

    //loop all the rows in the gridview
    foreach (GridViewRow row in gv.Rows)
    {
        //use findcontrol again to find the textbox
        TextBox tb = row.FindControl("tbScore") as TextBox;
    }
}
Related Posts Related Posts :
  • grab non-sibling element with jquery
  • Select a word and click it
  • Trigger modal instead redirect to /users/sign_in path, Rails 4 with devise
  • Combining Parent theme JS and CSS
  • Angular ui-grid - DropDown Selection shows Id
  • jquery addclass when there is content on body
  • JQUERY : CSS does not apply to dynamically created elements
  • Bootstrap multiselect dropdown checkbox not working on paginated table
  • JQuery scroll to dynamic id
  • Jquery first time tried ajax
  • Disable the link on the active tab (Bootstrap)
  • How to handle this validation when a div is added?
  • how to show/hide and check/uncheck checkboxes dynamically inside kendo grid
  • Conditional parameters for AJAX function
  • Jquery add class to input checkbox field
  • Bootstrap countdown timer Jquery
  • Open the closest modal of jQuery clicked element
  • change background color of specific button on click
  • Can I create link as post to 3rd party site and open in new tab?
  • ID is 'undefined' using .each()
  • Using .each() for targeting each child differently in Jquery
  • How to return data from functions in function
  • Execute this jquery only when viewport is bigger than
  • Bootbox showing white box behind dialog
  • Toggle multiple classes with prevAll(), nextAll(), slice(), and duplicate classes... better way?
  • Show/hide list items and add more/less link
  • Going through all occurences of class on slider change
  • Call jQuery valid() without updating the screen
  • hide and show ActionLink and save data in database - MVC
  • Pass each object in JSON array to query
  • Toggling content div on one-page site with jQuery
  • Foundation Equalizer is setting height to inherit?
  • carousel navigation each function
  • changing color of text color with input slider
  • jquery: filter using AND OR in selector
  • Call a function If any Item is chosen From select box , After Dom update
  • Target class within a jquery object
  • How to scroll a web page with fixed navigation bar just before arrive to a section or div?
  • How to add a class name to a specific selector
  • How to prevent background scrolling
  • How can I disable previous/next in OwlCarousel2 if there aren't enough items to scroll?
  • How to pass products and quantities to ASP.NET MVC4 Web API from form submit
  • jQuery css3 attribute not working
  • WordPress One Page Style Menus Scrolling
  • jquery.unobtrusive-ajax.js is not capturing the Submit event
  • Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'
  • can't get correct checkbox value
  • jquery tooltipster plugin, hide all tips?
  • How to set 3 different colors at jQuery UI Slider
  • How to convert a string to html and add a event, descard after use?
  • How can I make jQuery wait for div display value to change to "block", then make ajax call?
  • Stellar.js giving uncaught type error
  • Saving form data to local storage and show it on refresh
  • Jquery carousel not being implemented
  • Use modal with external URL body and dynamic links from data attribute
  • Looking to simplify my jquery
  • Bootstrap datepicker query?
  • Navbar/header animated change on scroll
  • Bootstrap paginated table sending only 10 row's data to server
  • Bootstrap 3.0 & NiceScroll 3.5.0
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org