Interested in incorporating dynamic calendar entries in ASP C#?

Here is the code snippet I utilized:

<script>
    var count = 1;
    var limitValue = 3;
    function addNewInput(sectionName) {
        if (count == limitValue) {
            alert("You have reached the limit of adding " + count + " inputs");
        }
        else {
            var newSection = document.createElement('div');
            newSection.innerHTML = "Experiment Date" + (count + 1) + " <br><input type='text' name='myInputs[]'>";
            document.getElementById(sectionName).appendChild(newSection);
            count++;
        }
    }
</script>

Below is the HTML markup:

<body>
<form name="form1" runat="server">
     <div id="dynamicInput">
          Experiment Date 1 <br/> <input id="demo2" type="text" readonly="true" name="myInputs[]" runat="server"/>
     </div>
      <asp:Button ID="Button8" runat="server"  Text="Add more Experiments" onclientclick="addNewInput('dynamicInput')"/>

</form>

I've also implemented a date picker for calendar entries. However, upon running the page, I encountered an issue where the added division disappears shortly after being generated. It seems to be related to a problem with page loading. Can you suggest a solution to this? Additionally, as my original form requires multiple entries, can this method be applied there as well? Are there any alternative solutions available? Thank you for your attention.

Answer №1

<input type="text" class="form-control" id="datepicker1" value="yyyy-MM-dd" name="datepicker1"/>
                    <script type="text/javascript">
                        $('#datepicker1.form-control').datepicker(
                            {
                                dateFormat: "yy-mm-dd"});
                    </script>

This code snippet includes a bootstrap form control element with a datepicker feature.

To retrieve the selected date in C#, you can use the following code:

string datepicker = Request.Form["datepicker1"];

I hope this information is helpful to you. Feel free to reach out if you need further assistance.

Answer №2

Great news - your code is functioning perfectly! The only modification I made was:

<input ID="Button1" type="button"  value="Add" onclick="addInput('dynamicInput')"/>
Additionally, consider assigning an id to any new input elements added via JavaScript to simplify data retrieval in the future.

Hopefully this information proves helpful!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular's UI Modal: utilizing inline template and controller functionality

I am looking to create a simple confirmation box using UI-modal, which I have used successfully for more complex modals in the past that load their template and controller from external files. However, this time I want something even simpler - just a basi ...

Use JavaScript to upload a JSON file containing arrays into separate tabs

Looking for help with incorporating JSON data into an HTML template that features tabs and a gallery? Take a look at my setup below: <div class="tab"> <button class="tabLinks" onclick="openDiv(event, 'overview'); appendData()" id= ...

Exploring the proper syntax of the reduce() method in JavaScript

Here are two codes that can be executed from any browser. Code1: let prices = [1, 2, 3, 4, 5]; let result = prices.reduce( (x,y)=>{x+y} ); // Reduces data from x to y. console.log(result); Code2: let prices = [1, 2, 3, 4, 5]; let result = prices.red ...

Ways to incorporate vector .svg images into a D3js tree diagram

var treeData = [ { "name": "Top Level", "parent": "null", "remark":"yes", "children": [ { "name": "Level 2: A", "parent": "Top Level", "remark":"yes", "children": [ { "name": "So ...

Utilizing Node.js ORM2 callback functions with custom parameters

Currently, I am developing models using a for loop: for (var j = 0; j < data.length; j++) { models.MyModel1.create({ name : data[j].name }, function(err, model){ if (err) { throw err } ...

search for a specific value within a nested subfield of an asterisk star field in Firestore

Here is the data I have: { root: { _rEG: { fen: 'value' }, _AS: { fen: 'value' }, _BSSA: { fen: 'value' } } } I would like to query using where('root.*.fen', '==', 'value'). ...

Navigating advanced search through nuanced filters dynamically with AngularJS

Here you will find the advanced search form: https://i.stack.imgur.com/g7Hiz.png I have successfully created a URL and parameters for document sections, but I am struggling to come up with a solution for managing the "Add Property Restrictions" section w ...

How to Enhance GraphQL Mutation OutputFields with a Function Generator

I'm encountering issues while trying to incorporate a function generator within a GraphQL mutation. The function generator is utilized to streamline the promise chain inside the mutation. Prior to refactoring the code, everything was functioning corr ...

Ways to establish a minimum height for material cards using Material UI

I am facing an issue with a card that contains a nested table. The card expands and shrinks based on the size of the table inside it. I want to prevent the card from shrinking when the table has no data or just one entry. Instead, I need the card to mainta ...

Are you ensuring compliance with licensing in your Webpack bundles?

Can webpack be used to verify license compliance? I'm looking for a way to ensure that the license headers from all modules built by webpack are included in the final output file. How can we confirm this is happening? Furthermore, I am also intereste ...

Guide on using Ajax and spring MVC to dynamically fill a modal form

One JSP page displays database results in a table on the browser, allowing users to edit or delete each row. I want to implement a feature where clicking the edit link fetches specific customer data from the database using Spring MVC and Hibernate, display ...

Changing the value of an object property (illustrated using a basic linked list)

I am working on a JavaScript Link List implementation as a beginner, and I have written the following code: var LinkList = function () { this.LinkedList = { "Head": {} }; }; LinkList.prototype = { insert: function (element) { var Node = this ...

reduce the size of the image as the browser width decreases

Struggling with a webpage layout that features an image on the left and content area on the right, both with fixed widths. When reducing browser width, the image should not shrink but be cropped from the left side instead. Any solutions for this issue? ...

Guide to automatically sending users to a subdomain depending on their IP address location

Currently, my website is built using Node Express and I have a specific requirement. I want to redirect users to different subdomains based on their current location. For example, if a user in Singapore accesses site.com, they should be redirected to sg. ...

Obtaining the width of a scrollbar using JavaScript in the most recent version of Chrome

Looking for a way to determine the width of the scrollbar using JavaScript for CSS purposes. I attempted the following: document.documentElement.style.setProperty('--scrollbar-width', (document.offsetWidth - document.clientWidth) + "px" ...

Managing errors through middleware functions

Currently, I've been studying node.js on and off. I came across this question: Middleware 1: app.use(function(req, res, next) { db.load(function(err, session) { if (err) { return next(err); } ... }); }); Middleware 2: app.u ...

Router DOM in conjunction with Next.js

I am attempting to extract the output of the code in navigation, but unfortunately it is generating a dreadful error: Unhandled Runtime Error Error: You cannot render a <Router> inside another <Router>. You should never have more than one in ...

What is the method for asynchronously loading a javascript file that includes an ajax call?

Within my JavaScript file named JScript.js, there is a function that includes an AJAX call to a dot-net page. alert('jscript.js called'); function AddTag() { var htag = document.getElementById("hdntag").value.split('|'); var texttag = ...

Capturing the MulterError

While using Multer, I encountered an issue with returning a custom error if a file already exists. My current approach involves using "cb(new Error('Flyer already exists'));" within a callback function when the file is detected as existing. Howev ...

Adjust div height to match the dynamic height of an image using jQuery

I'm facing an issue with my image setup. It has a width set to 100% and a min-width of 1024px, but I can't seem to get the 'shadow' div to stay on top of it as the window size changes. The height of the shadow div also needs to match th ...