Is there a way to select a specific GridViewRow using the AJAX.Net Toolkit PopupExtender?

I need to efficiently display a large amount of data in a GridView. Due to the abundance of information in each row, I am looking for a way to show additional details when a user clicks on a specific row. The PopupExtender from the AJAX Toolkit seems like the perfect solution for this case.

My goal is to have the popup appear whenever any control within the row is selected. While I have successfully attached the PopupExtender to a single control within the row, I am facing difficulties attaching it to the entire row itself.

I attempted to set the PopupExtender's TargetControlId to the Row's ClientID during the RowDataBound event, but encountered a runtime error:

TargetControlID of 'popupExtId' is not valid. 
A control with ID 'gvList_ctl02' could not be found.

I noticed that the rendered GridViewRow's tr element does not include an id attribute. To address this, I extended the GridView control by overriding the CreateRow method to render the row's ID (e.g. gvList_ctl02). However, even after making these changes, I continued to face the same runtime error when reintroducing the PopupExtender into the code.

I also attempted to bind the showPopup() javascript command to the row's onclick event to manually trigger the popup display. Despite successfully registering the click event and triggering it, the popup still did not appear.

Is there a way to properly bind a PopupExtender to a GridViewRow?

This is my current row bound code:

protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
{
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
  // Bind the popup extender's target ID to the row ID
  // This attempt results in a runtime error
  PopupControlExtender pop = e.Row.FindControl("popupExtId") as PopupControlExtender;
  pop.TargetControlID = e.Row.ClientID;

  // Attempt to bind the client-side click handler to show the popup
  // The alert is triggered without a javascript error, yet the popup remains hidden
  e.Row.Attributes.Add("onclick", "alert('Row Clicked'); $find('" + pop.BehaviorID + "').showPopup();");
 }
}

Thank you for any insight or assistance.

Answer №1

If you're looking for a creative way to trigger modal popups within a grid view using ajax ModalPopupExtender, I have a clever solution involving some javascript and hidden button clicks. I set my modal popup extender's target control id to a hidden button, then use javascript to simulate a click on the hidden button in order to show the modal popup.

Check out the markup for my modal popup and hidden button below:

<asp:Button ID="hiddenButton" runat="server" Text="" style="display:none"></asp:Button>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender2" runat="server"
TargetControlID="hiddenButton" PopupControlID="Panel1" CancelControlID="CancelButton"
BackgroundCssClass="modalBackground" Drag="True"/>

And here's the javascript function that triggers the popup:

function showModal(btnID) {
btn = document.getElementById(btnID);
btn.click();
}

In my rowdatabound event, I call the javascript function showModal when a button is clicked:

Button myButton = (Button)e.Row.Cells[9].Controls[1];
matchButton.Attributes.Add("onclick", "showModal('" + hiddenButton.ClientID + "');

I hope this approach helps guide you in the right direction for implementing modal popups within your grid view.

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

Divide and conquer- Lighttpd's mod_wstunnel combines separate messages by using UNIX socket communication to the backend server

In my experience with lighttpd's mod_wstunnel, I have encountered a peculiar issue. When I send two messages in quick succession from the backend using a UNIX socket to communicate between lighttpd and the backend, I noticed that lighttpd logs show th ...

Implementing a night mode switch in a Vuetify application version 2.0 built on Nuxt.js

I have integrated the nuxt.js vuetify template, and within the nuxt.config.js file, there is an object (shown below) that sets up the dark mode for the application. vuetify: { customVariables: ['~/assets/variables.scss'], theme: { ...

JavaScript has the ability to manipulate the width of an element by using methods to both retrieve

I have a unique situation where I need to dynamically adjust the width of a ul list element based on the text content inside it. Specifically, I want the width of the ul list to be equal to the width of the first list item, which can change frequently. My ...

Incorporating SVG line elements into a line graph

After successfully creating an interactive line chart using nvd3, I am now looking to enhance it by adding an svg line to represent a baseline. Within my function that constructs and displays the line chart, I have the following code: function _buildGrap ...

Is it possible to interchange image src once the page has finished loading?

My current dilemma involves an image that is being inserted into my website through a third-party script: <img src="https://example1.com/image1.png" id="image1"> What I am trying to achieve is replacing this initial image with another one, like so: ...

Guide to changing the class of a particular child element when the parent element is clicked with vanilla JavaScript

Upon clicking the parent button, a class within its child element will toggle to show or hide. If the child element is selected, a loading animation will appear for a brief moment before reverting back to its original hidden state. I attempted to achieve ...

Is it possible to delete an element from both local storage and HTML by referencing its ID?

Experience a simple flashcard game where you enter a question and answer to create a new flash card stored as an object within the cards array. The newly created flash card is also displayed by appending a new element to the flash cards section on the webp ...

Uploading files in React.js using Yii2 API

I am working with react.js (version 15) and I need to upload files using yii2 api. Here is my code: My component in react: import React, { Component } from 'react'; import Header from './Heaader'; /* global $ */ class New ...

Dynamic Positioning in Javascript Application

When working on a javascript project, I needed to create a div element. Here is the code snippet I used: const divStyle = {left: offsetPercent + '%', 'position': 'absolute'}; <div style={divStyle}/> However, I encounte ...

Does expressJS use the express() function as a global function?

Can anyone confirm if the express() function used in the second statement is a global function? I have searched my project folder but couldn't find its declaration. var express = require('express'); var app = express(); var fs = require("fs ...

managing data in an uncomplicated manner

In my website, users can select animals from a database without the page reloading. For example, under the category "Brown Animals," a user might choose "kittens" by checking a checkbox. Later, when browsing through "Cute Animals," if "Kittens" is displaye ...

How can you programmatically deselect all checkboxes in a list using React hooks?

I am facing a challenge with my list of 6 items that have checkboxes associated with them. Let's say I have chosen 4 checkboxes out of the 6 available. Now, I need assistance with creating a button click functionality that will uncheck all those 4 sel ...

Assign value to twig variable using JavaScript in Symfony version 3.4

Hello everyone, I am currently working on a form that is functioning well. However, I am facing an issue with setting the localization of a place manually using latitude and longitude values. To address this, I decided to create a map with a draggable mark ...

Utilizing JavaScript-set cookie in PHP: A comprehensive guide

I am currently facing a situation where I am setting a cookie using a JavaScript script on my page, but I need to access this value while generating HTML on the server-side using PHP. Let me explain the scenario. When a user requests a page, PHP star ...

Displaying a collection of items using ReactJS

Hey there! I have an array of objects containing comments for a particular item, and I only want to display the first 10 on the page. Below that list, I'm looking to add a button that allows users to see the next set of 10 comments when clicked. It&a ...

The function WebForm_DoCallback is not recognized

Encountering an error where WebForm_DoCallback is undefined. UPDATE WebForm_DoCallback("AccountPageControl1", "FileSave~" + fileName, CVFileSavedServerResponse, null, null, true); function CVFileSavedServerResponse(param, context) { } Why isn't ...

Is there a method to consistently implement a controller function across all routes within a router file in Express?

I have the following code snippets within an application. I am looking for a way to apply "authController.isLoggedIn" to each instance of "router.get" without having to repeat it multiple times. Initially, I thought using router.use might be the solution ...

Highcharts gauge removing unnecessary white borders

I have created a highchart gauge code that looks great on JSFiddle, but when I paste it into my website, the 'border' options (borderColor and borderWidth) don't seem to work. The browser automatically adds white borders to my series, toolti ...

Ways to stop the react-router from causing the page to refresh

Need assistance with React Router issue I'm working on a project in reactJs using react-router-dom v5. I have set up a default route for routing. <Redirect to={"someComponent"}/> The problem is that when I refresh the page, it auto ...

Utilizing JavaScript Classes to Implement Multiple CKEditor Instances

I have been attempting to utilize CKEDITOR for editing the content on my website. However, I am unsure about how to handle multiple instances of CKEDITOR. I have encapsulated all the JavaScript functions in a Class, but I need assistance in determining whi ...