Sam
Sam

Reputation: 146

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...

Upvotes: 1

Views: 1103

Answers (2)

Bjørn
Bjørn

Reputation: 1148

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.

Upvotes: 0

AliRıza Adıyahşi
AliRıza Adıyahşi

Reputation: 15866

try this :

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

Upvotes: 1

Related Questions