简体   繁体   中英

How can i change image path on click for asp.net dynamic content

I am using jquery for changing image path but its not working for asp.net dynamic content

The jquery function is

$('img.selection').click(function () {

this.src = 'images/selected_img.png';
});

This function is not post backing in to the C#, so am not getting changed image values.
Please help me...

try this:

$(this).attr("src", 'images/selected_img.png');

The problem might lie in that asp controls id's are changed when sent to the client.

If this is the case you can fix this in to ways

  1. Set the controlidmode to static on your control in asp.

  2. get the id of the control with jQuery with selectors: $('[id$=theidnameofthecontrol]').click(function ()....

Also you do not need postback. If you provide the new url with jQuery, it should load this without having to postback.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM