Tips on accessing the value of a dynamic field in an ASP ModalPopup

I am having trouble with my modalpopup extender. When the user clicks an 'Add' button, a dynamic textbox is created within the popup. However, I am struggling to get a reference to this textbox in the codebehind.

Adding a 'textchanged' event handler to the textbox does not work as expected. Since it requires AutoPostBack to be true, the modalpopup is destroyed before the event fires. Even if I try to reshow the modalpopup, the dynamic field disappears.

Here is the ASP code for the modalpopup:

<asp:ModalPopupExtender ID="PayDetail_ModalPopupExtender" runat="server" PopupControlID="PayDetailPopupPanel" TargetControlID="btnShowDetailPopup"
                    CancelControlID="btnClosePayDetail" BackgroundCssClass="modalBackground">
 </asp:ModalPopupExtender>

 <asp:Button ID="btnShowDetailPopup" runat="server" style="display:none" />
 <asp:Panel ID="PayDetailPopupPanel" runat="server" CssClass="modalPayPopup" align="center" style = "display:none">
                        <asp:table id="addClaimDetailTable" runat="server" class="table" >
                            <asp:TableRow style="display:none">
                                <asp:TableCell >
                                    <asp:Label ID="lblPayHeaderID" runat="server" Text="Pay Header ID:"></asp:Label>
                                </asp:TableCell>
                                <asp:TableCell >

                                    <asp:TextBox ID="txtPayHeaderID" runat="server" Enabled="false"></asp:TextBox>
                                </asp:TableCell>
                            </asp:TableRow>
                        </asp:table>
 </asp:Panel>

To create a dynamic textbox in the codebehind:


        TableRow tRow = new TableRow();
        TableCell hCell = new TableCell();
        TableCell dCell = new TableCell();

        Label lblHeader = new Label();
        lblHeader.ID = "lblMedicare";
        lblHeader.Text = "Medicare:";
        TextBox txtData = new TextBox();
        txtData.ID = "txtMedicare";
        txtData.Text = "";
        txtData.TextChanged += new EventHandler(txtData_TextChanged);
        txtData.AutoPostBack = true;

        PayDetailDynamicList.Add(txtData);

        hCell.Controls.Add(lblHeader);
        dCell.Controls.Add(txtData);
        tRow.Controls.Add(hCell);
        tRow.Controls.Add(dCell);

        addClaimDetailTable.Controls.Add(tRow);

The textbox is stored in a static list:


     static List<TextBox> PayDetailDynamicList = new List<TextBox>();

And here is the codebehind for the eventhandler:


    void txtData_TextChanged(object sender, EventArgs e)
    {
        TextBox t = sender as TextBox;

        if (t == null)
            throw new ArgumentException("sender not a textbox", "sender");

        string value = t.Text;
        string id = t.ID;
    }

I need help figuring out how to store the user-entered data or get a reference to the dynamic textbox. Any suggestions on better ways to achieve this are appreciated. Thank you!

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

Utilizing Ajax to fetch a div element from a web page

Hey there! I have a link set up that loads a page into a specific div ID, which is #ey_4col3. The issue I'm facing is that it loads the entire page along with all its contents, but what I really want to load from that page is just the content within ...

Two flexible-sized containers placed side by side, with an ellipsis displayed on the left container

Can you achieve a layout where two elements are inside a container and float side-by-side? The right element should adjust its size based on the content while the left element fills the remaining space in the container with an ellipsis to truncate overflow ...

Enhancing the KeyValuePair by incorporating additional value or parameter

I currently have a List<KeyValue<string, int>> that I utilize in the View of one of my applications. While it functions as intended, I am interested in expanding it by potentially incorporating an additional parameter/value to the KeyValue pair ...

Show the image on top of the div block as the AJAX content loads

Implementing this task may seem easy and common, but I am struggling to figure it out! What should take five minutes has turned into an hour of frustration. Please lend me your expertise in getting this done. I have a div container block: <div cla ...

Upon the initial hover, the data added to the title tag following an Ajax call is not appearing

I am currently working on an ajax request that retrieves information such as username, email, and user_id. Once the ajax call is successful, I use jQuery to append this data to the title tag. The main issue I am facing is that the data is only displayed af ...

Is there a method, like using jQuery, to insert `<br>` tags into each line of a dropdown select list?

I need help with implementing a select tool in a limited horizontal space with each line containing a lot of information. I attempted to embed a tag into the line but it didn't work. Are there any solutions available that could provide a simple fix ...

Tips for Implementing Multi-Level/Nested in Ajax Requests

I am currently developing a user-friendly web application with intuitive multi-level options that loads new content without the need to refresh the entire page. This is how my structure looks: /index.php /schools.html /colleges.html Within schools.html, ...

Using jQuery and Bootstrap in an ASP.NET Core project

I am encountering an issue with the configuration of bootstrap and jquery within my project, causing these tools to fail to load properly. The problem seems to be that bootstrap is loading before jquery, resulting in error messages appearing when I check ...

Ensure the footer remains at the bottom of the page even with changing

I am encountering an issue with positioning a footer under dynamic content displayed in a div named txtresults. The div is updated with HTML following a query made with an input value, as shown in this example on JsFiddle: JsFiddle Currently, I am struggl ...

Inject CSS values dynamically

I am currently working on dynamically setting the color of a div. To provide some context, let's examine the following: <!doctype html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <div clas ...

Ways to showcase INPUT TYPE when making a Selection?

I've been struggling with a simple issue and despite trying multiple solutions, I can't seem to get it right. I have a form where I'm using the <select> tag with two options: coo and uh. What I want is for an additional input type fiel ...

Adding a CSS style to specific sections of a string that is quoted in a Razor ASP.NET file

Is it possible to format a specific part of a string? I'm trying to only stylize the word within quotation marks. This is my cshtml code: { <div class="h-44 overflow-auto text-left mx-4 mb-4"> <p ...

Real-time Data Stream and Navigation Bar Location

Utilizing the EventSource API, I am pulling data from a MySQL database and showcasing it on a website. Everything is running smoothly as planned, but my goal is to exhibit the data in a fixed height div, with the scrollbar constantly positioned at the bott ...

Unable to implement CSS styles on the provided HTML code

I'm currently working on integrating evoPDF into my asp.net application. When I click on a part of the HTML file, I send that portion using AJAX. So far, everything is working well up to this point. However, when I try to use the following methods fro ...

Is it possible to iterate through div elements using .each while incorporating .append within an AJAX call?

After sending AJAX requests and receiving HTML with multiple div elements (.card), I am using .append to add new .card elements after each request, creating an infinite scroll effect. However, I am facing issues when trying to use .each to iterate over all ...

Traversing JSON Data using Vanilla JavaScript to dynamically fill a specified amount of articles in an HTML page

Here is the code along with my explanation and questions: I'm utilizing myjson.com to create 12 'results'. These results represent 12 clients, each with different sets of data. For instance, Client 1: First Name - James, Address - 1234 Ma ...

Using jQuery AJAX to preload GIF images for CSS background-image loading

For some time, I have been utilizing jQuery AJAX to preload GIF images with the following code: $("#images").html("<img id='loader' src='../img/ajax-loader.gif' />"); Now, I am attempting to achieve a similar effect (such as a s ...

What could be the reason for the navigation bar menu items not showing up in the sample application of the twitter.bootstrap.mvc4 package?

After setting up a new MVC4 web application project in VS2012, I decided to add the http://www.nuget.org/packages/twitter.bootstrap.mvc4.sample/ nuget package. However, upon running the sample application, I encountered an issue where the navigation menu i ...

Having trouble retrieving the routeName as it consistently returns empty

I attempted to extract the routeName from the URL in order to apply a different class to the body's layout when on the /Category page. https://i.stack.imgur.com/J0hsp.png @{string classContent = Request.QueryString["routeName"] != "/ ...

jQuery does not trigger background image change in Webkit

const displayPreviewImage = (imageUrl) => { $('#slideshow-container').css("background-image", `url('files/images/store/content/templates/websites/preview_images/${imageUrl}'`); } I have a function here th ...