When you click anywhere on the page, JavaScript's method __dopostback is triggered

I'm encountering an issue in my asp.net application where I have an html table. Specifically, when a user clicks on a td element within the table, I use JavaScript to store the id of that td element in a hidden field. Afterwards, I trigger __dopostback from JavaScript in order to utilize the value stored in the hidden field in the code behind.

Here's a snippet of the HTML:

<td id="m1" onclick="">Jan</td>
<td id="m2" onclick="">Feb</td>

The JavaScript code looks like this:

$('.window td').on('click', function () {
        var idName = this.id;
        var selectedid = idName.substring(1);
        console.log(selectedid);
        $('#hidden').val(selectedid);
        _doPostBack(idName , '');
});

My current problem is that whenever I click anywhere on the page, it triggers the __doPostBack method. However, I only want this method to be called when a td element is clicked.

Does anyone know how to prevent __doPostBack from being triggered when the user clicks elsewhere on the page?

Answer №1

Issue resolved! Upon discovering additional tables on the page with the "window" class, I made a simple name change which successfully fixed the problem.

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

Adding colors dynamically upon page reload with javascript and jQuery

I have created an array of colors and am attempting to use colors.forEach inside the ready function to call addBox for each color in the array. My goal is to ensure that all the colors are added when the page is reloaded. Please let me know if you require ...

What is the best way to adjust the CSS height of an HTML select element to 100% within a table cell in Internet Explorer

Is it possible to make a select (dropdown list) element fill out 100% of the table cell height? I was successful in getting it to work in Firefox and Chrome, but unfortunately not in IE (Internet Explorer). Here is the test HTML code: <table> & ...

Trigger an event prior to the loading of a div

I have been working on a jQuery code that needs to run just before a specific div is displayed on the page. Take a look at the snippet below as an example of what I am trying to achieve: $(document).ready(function(){ $('.article').on('m ...

Executing a 'WebMethod' using jQuery in ASP.NET WebForms

I've placed a breakpoint inside the WebMethod below, but it never seems to get hit. cs: [WebMethod] public static string search() { return "worked"; } aspx: function search() { $.ajax({ type: "POST", url: "ProcessAudit/re ...

Any ideas on what I might be doing incorrectly that's causing this div to not be perfectly centered? It seems a bit

I need help centering a div horizontally to a marker. I have been following this example here http://jsfiddle.net/rKejG/8/, but it seems to be slightly off to the right. Here is my code: $("#infobox").css({ marginLeft: (parseInt($("#content").width() ...

Using the spread operator in React to distribute JSX elements within a map function

I am struggling with mapping over an array within another array to create a Picker and am having difficulty returning JSX elements instead of an array of JSX elements. Here is the code example: {modelA.map((mA) => { const pickerItems = mA.modelB.m ...

Text that appears when you hover over specific locations within one image

https://i.sstatic.net/G1uWk.png I need assistance in creating a feature where users can see short descriptions of individuals in a photo when hovering over them (not like a tooltip). I attempted to use an area map but encountered difficulties in implement ...

How to dynamically insert variables into a separate HTML file while creating a VS Code extension

Currently working on a vscode extension, I'm facing an issue with containing the html in a string (like this: https://github.com/microsoft/vscode-extension-samples/blob/main/webview-view-sample/src/extension.ts). It leads to a large file size and lack ...

Develop a responsive design for a row of icons that automatically flows to a second line when the screen size is

Currently, I am utilizing Bootstrap 4 and attempting to design a row of 12 icons that are responsive. <div class="app-container"> <div class="row"> <div class="col-md-1"> <a class="" href="https://www.xxx.org.au"> < ...

Updating button appearance when clicked using Vue.js and Tailwind CSS

As part of my learning journey, I have expanded this code to enhance my frontend skills. While I am aware that the code can be significantly shortened, I am focused on learning and broadening my experience in frontend development. The code below functions ...

The DataField linked to the databound is failing to populate with data

Right now, I am diving into the code of a web application. The initial page contains a GridView with multiple data fields that are supposed to be populated with data based on a URL parameter when the page loads or reloads. Here's how it all works: -W ...

Unable to send a post request using ajax

Section of Form in home.php <div id='googleForm'> <form> <div class='item'> <label class='label'>Full Name</label> <input class=&apos ...

Retrieve the browser version of a client using C# (When Internet Explorer Compatibility mode is activated)

Is there a way to retrieve the actual version of the client's browser from C# code? Using Request.Browser or HTTP_USER_AGENT provides details, but in Internet Explorer (IE), when compatibility mode is enabled, it always returns IE 7 regardless of the ...

Challenges with managing controllers within Directives

Currently, I am in the process of updating some code within a personal project that utilizes Angular to adhere to best practices. I have come across suggestions that the future direction of Angular involves incorporating a significant amount of functionali ...

Incorporating geocoding functionality in an asp.net mvc project and looking to efficiently transfer latitude and longitude data from JavaScript to a controller function

UPDATED. Following your suggestions, I implemented the function as shown below: [HttpPost] public ActionResult populate_place(string lati, string longi) { list_placesModels list_place = new list_placesModels(); list_place.Latitude = lati; li ...

Is it possible to load asynchronous JS and then execute functions?

Is there a way to make my script behave like the Google Analytics JavaScript snippet? Here is an example of what I have: (function(d, t) { var g = d.createElement(t), s = d.getElementsByTagName(t)[0]; g.src = 'myjs.js'; s.par ...

The Carousel is covering up my Mega-Menu and it is not visible on top

I'm facing an issue where my mega menu is hidden behind the carousel, and I need it to show on top. You can see how it looks before adding the carousel and after adding the carousel from Bootstrap. Here are the links to the Mega Menu CSS and Mega menu ...

Revamping the current text for the circle feature in ProgressBar.js

I am working on a project where I use ProgressBar.js to generate a circle with a percentage displayed in the center. While the circle renders correctly initially, I'm facing an issue when trying to update the text (percentage) after running it again w ...

Issue locating the bottom of the scroll bar

My attempt to detect when the scroll reaches the bottom of a div involves using this code: $('.scrollpane').scroll(function(){ if ($(this).scrollTop() + $(this).height() === $("#results").height()) { alert('scroll at bottom&a ...

Encountering an error while attempting to load the jQuery script: TypeError - $.fn.appear.run is not a

I have included an animation script for CSS in my markup, but I am encountering the following error: TypeError: $.fn.appear.run is not a function Does anyone know why this is happening and how I can resolve it? /* * CSS3 Animate it * Copyright (c) 2 ...