How to eliminate a div using jQuery

Within a repeater, there is a button that should remove the respective div followed by a database query using AJAX when clicked. The issue arises when attempting to remove the div in the success part of the AJAX call.

Here is the code snippet:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" >
                        <ItemTemplate>
                            <div class="grid_4" data-gen="afc" data-gen-offset="bottom-in-view" id='<%#Eval("Id") %>'>
                                <a class="services-block" href="#">
                                    <ul class="icon">
                                        <li class="fontawesome-icon large circle-two fa fa-laptop"></li>
                                        <li class="fontawesome-icon large circle-deg-two fa fa-laptop"></li>
                                    </ul>
                                    <p>
                                        <asp:Label ID="lblGameTitle" runat="server" Text='<%# Eval("GameName") %>'></asp:Label></p>
                                    <div class="text">
                                        <asp:Label ID="lblOpponent" runat="server" Text='<%# Eval("OpponentOne") + "  Vs.  "+ Eval("OpponentTwo") %>'></asp:Label>
                                        <br />
                                        <asp:Label ID="lblDateTime" runat="server" Text='<%# "Date : "+ Eval("GameDate") + "<br />Time : " + Eval("GameTime") %>'></asp:Label>
                                        <br />

                                        <asp:RadioButton ID="rbtnBlue" runat="server" Text="High" GroupName="UrlColor" Checked="true" />
                                        <asp:RadioButton ID="rbtnRed" runat="server" Text="Low" GroupName="UrlColor" />


                                        <asp:Button ID="btnOpponentOne" runat="server" Text='<%# Eval("OpponentOne") %>' OnClientClick="opponentOne(this);"/>
                                        <asp:Button ID="btnOpponentTwo" runat="server" Text='<%# Eval("OpponentTwo") %>' OnClientClick="opponentTwo(this);"/>
                                        <asp:Button ID="btnDraw" runat="server" Text="Draw" OnClientClick="Draw(this);"/>
                                        <br />
                                    </div>
                                </a>
                            </div>
                            <asp:HiddenField ID="gid" runat="server" Value='<%# Eval("ID") %>' />
                            <asp:HiddenField ID="opOne" runat="server" Value='<%# Eval("OpponentOne") %>' />
                            <asp:HiddenField ID="opTwo" runat="server" Value='<%# Eval("OpponentTwo") %>' />
                        </ItemTemplate>
                    </asp:Repeater>
                   <%-- <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />--%>

                </ContentTemplate>
            </asp:UpdatePanel>

JavaScript function utilized for removing the div on button click:

function opponentOne(btn) {
            var s = btn.id;
            var start = s.indexOf("btnOpponentOne");
            var end = s.lastIndexOf("_");
            sub = s.substring(start, end);
            s = s.replace(sub, "opOne");
            var hidden = document.getElementById(s);
            var id = hidden.value;  
            var divId = aaaa1(btn);
            var check = CheckRadio(btn);
            var tid = getParameterByName('tid');
            var inputText = id + "~" + divId + "~" + check+"~"+tid;    

            if (confirm('Are you sure?')) {
                $.ajax({
                    type: "POST",
                    url: "/play_match.aspx/AddPrediction",
                    data: '{\'InputText\':\'' + inputText + '\'}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                        if (response.d == "Success") {
                            alert('done..............'+divId);
                            $('#' + divId).remove();
                        }
                    },
                    failure: function (response) {
                        alert('fail');
                        alert(response.d);
                    },
                    error: function (response) {
                        alert('error');
                        alert(response.d);
                    }
                });
            }

        }

Answer №2

If you need to update the UI in an update panel, be sure to manually refresh it. One way to do this is by using the __doPostBack(UpdatePanel1, ''); method. Best of luck!

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

Using Angular JS, send out a notification and pause execution until it is finished

I recently encountered an interesting situation involving an Angular event: $rootScope.$broadcast("postData"); doSomething(); However, I realized that doSomething() needs to wait for the completion of postData before executing. This led me to contemplate ...

Getting a Node Express 404 error while attempting to display an image that was uploaded using multer

I am facing an issue with uploading images using multer. Previously, everything was working perfectly fine on localhost. The images were getting uploaded and I could view them using the provided URL link in the code. However, after uploading it to a server ...

Ways to increase the values in a textbox

My task involves handling checkboxes that are populated with data from a database. The goal is to have certain checkboxes pre-checked based on the retrieved data, and if any are not checked, their values should be entered into a textbox. For instance, con ...

What is the ideal method for creating multi-view layouts in ASP.NET MVC?

I've been pondering the best approach to create multi-view layouts using ASP.NET MVC. For instance, in angular-based SPAs, loading different views into a layout is quite simple: <div ui-view="header"></div> <div ui-view="content">& ...

Search for Div IDs while filtering as you type

Is there a search jQuery plugin that enables real-time filtering based on Div ID as you type in the search box? It would be great if the filter instantly refreshes. ...

Troubleshooting a Custom Pipe Problem in Angular Material Drag and Drop

Currently, I am working on a project involving Angular Material Drag And Drop functionality. I have created a simplified example on StackBlitz which you can access through this link: here The project involves two lists - one containing pets and the other ...

Embrace the presence of null values on the client side

When utilizing the code below, I can determine the location of logged-in users. However, there are some users who do not have a specific location assigned. For example, Administrators are common for all locations. In such cases, how can I set it so that ...

When attempting to execute a function within another function in JavaScript, a ReferenceError is triggered

I recently developed a straightforward app that utilizes the Google Drawing Library (https://developers.google.com/maps/documentation/javascript/examples/drawing-tools) to allow users to draw circles on a map. The first circle represents the source locatio ...

Converting a Perl hash into a JavaScript hash: A comprehensive guide

I am currently using the template toolkit framework and working with a Perl hash data type in my tt file. My goal is to convert this Perl hash data type into a JavaScript hash data type. Code: template: [% PERL %] use JSON qw(encode_json) ...

Tips for achieving seamless scrolling with the combination of javascript and css

Looking for a solution to achieve smooth scrolling on an HTML page without using the #id_name to scroll to a specific div. Instead, I want to scroll to a particular point, such as having a button that scrolls down the webpage smoothly by 250px when press ...

Displaying multi-dimensional arrays through the console in JavaScript and showcasing their elements

My array is supposed to have 140 indexes in a single format like this: array:[0-140] //however, it currently appears as: array: [ 0: [0-99], 1: [100-140] ] I've confirmed multiple times that it is just one array of objects. Why is it s ...

Manipulating JSON data in JavaScript

Currently delving into learning JSON as required for work purposes... I am attempting to dynamically add and delete records to a JSON object... Can anyone shed some light on why I keep receiving an UNDEFINED message? Here is the code... Appreciate any as ...

Is there a way to eliminate the # sign from hash data using jQuery?

Can anyone help me retrieve the hash value from the URL? var hash = window.location.hash; I am looking for a way to remove the "#" sign from the hash. Any suggestions? ...

Unlock real-time alerts with the power of JavaScript and PHP!

I am currently working on enhancing my skills in javascript. I have a basic idea of what I want to achieve. My goal is to create an automated javascript function that accesses a php page. This php page will create an array of new notifications for the ja ...

What steps should I take to fix an error in my code?

My current objective is to write a program that generates a square with dimensions of 200 pixels by 200 pixels. The square should be colored using specific RGB values: red (red value of 255), green (green value of 255), blue (blue value of 255), and magent ...

What is the best way to pass a dynamically generated component as the ng-content for another dynamically generated component?

Need help with creating a modal for our library using viewRef.createComponent. I want to generate Component A and embed Component B inside it, utilizing <ng-content> to fetch content from Component B. Component A serves as the modal template, while ...

Is there a way to verify user credentials on the server using FeathersJS?

Currently, my single-page app is utilizing feathers client auth and a local strategy for authentication. I have implemented various middleware routes and I am looking to verify if the user is authenticated. If not, I would like to redirect them to /. Bel ...

Extracting JavaScript variable data to PHP using Ajax technology

I've been trying to save latitude and longitude values in PHP variables, but I'm having trouble. Here is the code I'm using. Can anyone please help me figure out why these values are not being stored in PHP variables: Code: <!DOCTYPE h ...

Jquery Visualization Chart not displaying

I am struggling to get the jquery visualization to work properly. Although the table and caption appear fine, there is no data showing up in the chart. I've carefully followed the example and searched for any issues, but I can't identify what&apo ...

Do Material-UI pickers only validate on blur, not on change events?

When you type inside the DatePicker component, validation is triggered immediately. Is there a way to trigger validation on blur instead of onChange when using @material-ui/pickers with material-ui v4 Passing the value to the blur function should work a ...