Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 754001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:57:44+00:00 2026-05-14T14:57:44+00:00

I have an ASP.NET MVC application with pages where the content is loaded into

  • 0

I have an ASP.NET MVC application with pages where the content is loaded into divs from client via JavaScript/jQuery/JSON. The loaded content contains a-tags with references to a function that updates server side values, then redirects to reload of entire page even though.

I wish to replace the a-tags with ‘something’ to still call a server-side function, then reload the div only.

What is the ‘right’ way of doing this?

All comments welcome.

This is as far as I got so far. getResponseCell() returns a td-tag filled with a-tag.
I’ve mangled Glens suggestion into the .click() addition, but it just calls the onClickedEvent…

Code sample:

    onClickedEvent=function()
    {
        return false;
    }

    getResponseCell=function(label, action, eventId)
    {
        tmpSubSubCell=document.createElement("td");
        link = document.createElement("A");
        link.appendChild( document.createTextNode( label));
        link.setAttribute("href", "/EventResponse/"+ action + "/" + eventId);
        //link.setAttribute("href", "#divContentsEventList");
        //link.setAttribute("onclick", "onClickedEvent(); return false;");
        link.setAttribute("className", "eventResponseLink");
        
        
        link.click(onClickedEvent());
            
        // link=jQuery("<A>Kommer<A/>").attr("href", "/EventResponse/"+ action + "/" + eventId).addClass("eventResponseLink");
        // link.appendTo(tmpSubSubCell);
        tmpSubSubCell.appendChild(link);
        
        return tmpSubSubCell;
    }

And the solution that worked for me looks like this:

    onClickedEvent=function(event, actionLink)
    {
            event.preventDefault(); 

            $("eventListDisplay").load(actionLink);

            refreshEventList();                

            return false;
    }

    getResponseCell=function(label, action, eventId)
    {
        tmpSubSubCell=document.createElement("td");
        link = document.createElement("A");
        link.setAttribute("id",action + eventId);
        link.appendChild( document.createTextNode( label));
        actionLink = "/EventResponse/"+ action + "/" + eventId;
        link.setAttribute("href", actionLink);
        className = "eventResponseLink"+ action + eventId;
        link.setAttribute("className", className);

        $('a.'+className).live('click', function (event)
            {
                onClickedEvent(event,$(this).attr('href'));
            });

        tmpSubSubCell.appendChild(link);
        
        return tmpSubSubCell;
    }
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:57:44+00:00Added an answer on May 14, 2026 at 2:57 pm

    Without really seeing more information…..

    If you’re a’s are being added to the DOM after the initial page load, you cannot use the usual click() or bind() methods in jQuery; this is because these methods only bind the events to those elements that are registered in the DOM at the time the methods are called. live() on the other hand, will register the event for all current, and future elements (using the event bubbling mechanism in Javascript).

    $(document).ready(function () {
        $('a.eventResponseLink').live('click', function (event) {
            var self = $(this);
    
            self.closest('div').load('/callYourServerSideFunction.asp?clickedHref=' + self.attr('href'));
    
            event.preventDefault();
        });
    });
    

    We’re using event.preventDefault() to prevent the default action of the a-tag being executed; e.g. reloading or changing page.

    Edit: The issue won’t be caused by that. That’s the power of jQuery; being able to bind the same event to multiple elements. Check your HTML; maybe you’re missing a closing </a> somewhere? Maybe your binding the event in a location that gets called multiple times? Each time .live() gets called, it will add ANOTHER event handler to all matched elements. It only needs to be bound once on page load.

    jQuery provides loads of way for you to select the elements; check out the list. Looking at your link variable, it looks like all your links have a href starting with /EventResponse/; so you can use $('a[href^=/EventResponse/]') as the selector instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an ASP.NET MVC application I have a CartController with this AddToCart action: public
I have an ASP.NET 4.0 MVC web application running on IIS 6.0 with a
I have a wizard in my asp.net MVC application which is built upon this
I am using ASP.NET MVC application. However I am not able to understand the
Hi guys i know this is a known problem in ASP.NET MVC, basically what
Apologies, I'm new to ASP.NET MVC. :) I'm unsure if this is simple a
I'm finding myself hardcoding html into C#. It's usually on a data-driven pages. The
I don't know if this is an application configuration issue or an IIS issue.
I'm working on building a search engine in my application, and because I don't
[edit]: Figured out where it goes wrong. It has something to do with my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.