What is causing my rows to disappear even after I have made them visible?

There is a table with six rows, but initially only two are visible - a header row and one "business" row.

A button allows the user to add additional rows one at a time (making existing rows visible), up to a maximum of six rows / five "business" rows.

The code-behind sets rows 2-6 as invisible:

foapalrow3.Style["display"] = "none";

(the same for foapalrow4, foapalrow5, and foapalrow6).

To make these rows visible when the user clicks the "+" button, jQuery is used:

/* This makes the next hidden row visible, if there is one */
$(document).on("click", '[id$=btnAddFoapalRow]', function (e) {
    $('[id$=foapalhtmltable]').find('tr:hidden:first').show();
});

This functionality works correctly. However, upon form submission, the previously visible rows revert back to being hidden (except the first two). We need to ensure that any row containing input values remains visible. For example, if the "Index" column in each row has a value, they should be made visible again. The code snippet for this behavior is as follows:

// Expose any rows with values
if (RowContainsVals(3))
{
    foapalrow3.Visible = true;
}
if (RowContainsVals(4))
{
    foapalrow4.Visible = true;
}
if (RowContainsVals(5))
{
    foapalrow5.Visible = true;
}
if (RowContainsVals(6))
{
    foapalrow6.Visible = true;
}

UPDATE

After running the above code, the rows remain hidden even though they contain values. It seems like setting the visible property to true does not actually make them visible.

It's worth mentioning that manually expanding the rows using the "+" button reveals that the rows do indeed have the added values. So, the issue seems to be related to displaying them visually.

Answer №1

Consider updating your code to utilize Style["display"] = "table-row"; instead of Visible = true;

You mentioned that in the code behind, rows are hidden by using the style display:none.

It's important to note that in asp.net, making a control.Visible does not have the same effect as hiding it with a style.

Control.Visible = false will prevent the HTML code from being rendered on the Client Side, while setting display:none will render the row with a style that hides it on the browser. Based on your description of hiding and showing rows on the client side, it seems like the rows need to exist on the client side, so I assume they are never set to Visible = false;

Answer №2

After making a few changes, my code now looks like this:

// Show rows that have values
if (RowHasValues(3))
{
    foapalrow3.Visible = true;
}
if (RowHasValues(4))
{
    foapalrow4.Visible = true;
}
if (RowHasValues(5))
{
    foapalrow5.Visible = true;
}
if (RowHasValues(6))
{
    foapalrow6.Visible = true;
}

...transformed into:

// Re-display rows containing values
if (RowHasValues(3))
{
    foapalrow3.Style["display"] = "table-row";
}
if (RowHasValues(4))
{
    foapalrow4.Style["display"] = "table-row";
}
if (RowHasValues(5))
{
    foapalrow5.Style["display"] = "table-row";
}
if (RowHasValues(6))
{
    foapalrow6.Style["display"] = "table-row";
}

This adjustment has proven to be effective.

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

Whenever I attempt to use .ajax to post to an MVC 4 controller, the ViewModel is consistently null

My jQuery/HTML: @using(Html.BeginForm("Create", "Home", FormMethod.Post)) { <input name="ImageName" id="ImageName" type="hidden" /> <input name="XPos" id="XPos" type="hidden" /> <input name="YPos" id="YPos" type="hidden" /> ...

The Streams property does not have the 'Information' property at compile time in the Powershell instance

Having a rather peculiar issue. I wrote this C# PowerShell code using VS2015 and .net 4.52, which runs a script and captures the output like so: using (PowerShell powerShellInstance = PowerShell.Create()) { powerShellInstance. ...

Exhibition: Sequential Images Transition Using JQuery

Hey there! I've been experimenting with fading images in and out of this gallery. I tried using the following code: $('#slides').fadeTo(3000, 0.0); If you want to check it out, here's a link to my pen: https://codepen.io/anon/pen/gwRX ...

What steps do I need to take in order to arrange my cards into binary groups for PC viewing

Is there a way to display cards as binary groups for PC view? The layout looks fine on phone but the cards are all at the bottom when viewed on a computer. This is how it currently appears: https://i.sstatic.net/XBgJc.jpg I want the card layout to resem ...

What could be the reason for e.target.value being undefined?

Can someone explain why e.target.value is returning undefined when logged to the console in this simple component? The value should be defined within the element, so I'm confused as to why e.target is not giving the correct value. const NavBar = () = ...

Show and Arrange Various Key-Object Data pairs

I'm facing a challenge with mapping and displaying a JSON file in a different structure. I need help figuring out how to map the data properly. Here's the JSON file: var data = { "megamenu": [ { "name": "level1.2", "link": "#", ...

Using a jQuery function with onclick events in a loop

I'm faced with a challenge in jQuery/js programming and could use some guidance as I am relatively new to this. function initiateViewingProcess(){ var elen =$MP.data.REG_AS_RS.ASSIGNEE.length; for (i = 0 ; i < elen ; i++) {var dEv ...

Minimize all expanded containers in React

Although I've come across similar questions, none of them have addressed mine directly. I managed to create a collapsible div component that expands itself upon click. However, I am looking for a way to make it so that when one div is expanded, all o ...

The Vuex store variable is being accessed prior to being populated with information retrieved from the API

I am currently attempting to retrieve data from an API using Vuex. Below is the action function in the Vuex store: async getEpisodeFromApi({ commit }, id) { const data = { id }; return await axios.get(Api.getUrl(data)).then((res ...

Alter the arrow to dynamically point towards the location of the click source

I am currently working on creating a popover dialog that should point to the element triggering its appearance. The goal is for the arrow to align with the middle of the button when clicked. While I am familiar with using CSS to create pointing arrows, th ...

Is there a way to display this JSON data using mustache.js without needing to iterate through a

Here is the JSON data: var details = [ { "event": { "name": "txt1", "date": "2011-01-02", "location": "Guangzhou Tianhe Mall" } ...

Unprocessed Promise Rejection Alert: The function res.status is not recognized as a valid function (NEXT JS)

When I console.log(response), I see the result in the terminal. However, when I use res.status(200).json(response), I encounter an error in my Next.js project: Not Found in the browser. router.get("/api/backendData", async (req, res) => { dbConne ...

Ways to prevent text from wrapping in CSS

I'm currently in the process of creating a new website and I've encountered an issue with my CSS. It seems that whenever there is a space present, the text inside h2 tags wraps unexpectedly. You can visit the site here. Here's the specific ...

most effective method to link table header to corresponding table row within this specific data organization

In my current project, I have a table component that relies on two data structures to create an HTML table: one for the table schema (paymentTableMetadata) and one for the table data (paymentTableData). To simplify the process, I have hardcoded these data ...

Disabled button in Bootstrap4 displaying the wrong color as white instead of the intended color

On one of my pages, I have a bootstrap button that is disabled but the styling doesn't seem to be working correctly. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.mi ...

transferring a webpage to a collaborative platform

We currently have an intranet with numerous html pages and various attachments such as .doc and .xls files. We are contemplating migrating all of this to Confluence WIKI. Is there any script or automated tool available that can assist us in this migratio ...

Automatically Refreshing on Vue.js: Embracing the Passage of Time

I want to display this clock on Vue. The clock should automatically update the time, but how can I make this code work in Vue? Is there a simple way to implement this in Vue without using (document.getElementBy...) function updateTime () { document.ge ...

Can someone explain the meaning of the paragraph in the "Index Routes" section of the React-Router documentation?

Lesson 8 of the React-Router tutorial delves into the concept of "Index Routes", outlining the importance of structuring routes in a specific way. Here are some key points from their discussion: The tutorial suggests that while setting up the initial rout ...

What is the specific operation of this function?

Could someone clarify how this function operates? I have a grasp on the ternary operator, which checks if the flag is true and if not, then it uses the second value. However, I am unsure why flag is initially a Boolean and how it toggles between true and ...

The MongoDB bitwise operation does not return any results when checking for a

I am trying to perform a bitwise check on my data without returning any data. The default value for Rights parameter is 1. How can I resolve this issue? db.getCollection('forms').find( { "IsActive" : true, "$or" : [ { "$where" ...