Aspx image attributes are lost after changes via Javascript

Asked

Viewed 35 times

0

Insert an image with scr value and Descriptionurl defined in Aspx and I am changing the value of source(scr) and Descriptionurl (longdesc) via Javascript;

It turns out that after page_load the default values return and what was changed via javascript is lost.

In this case, what is the best solution?

ASPX and JAVASCRIPT:

function MudarCheckbox(id) {
  $("#" + id).attr("longdesc", "novaDescricao");
  $("#" + id).attr("src", "novaUrl");
}

//Aspx
Dim minhaImagem As Image = Page.Master.FindControl("ContentPlaceHolder").FindControl("minhaImagem")
//Obtem controller da img sem as alterações em JS
<asp:Image ID="minhaImagem" OnClick="javascript:MudarValor(this.id);" runat="server" ClientIDMode="Static" ImageUrl="minhaUrl" DescriptionUrl="minhaDescricao" />

  • Welcome to SOPT. Would like to [Edit] your post and add the code you are using, so we can analyze and suggest a change. Thank you.

  • Confirm if I understand correctly, you are modifying the image by javascript but then when you access the page by code Behind continues with the old image in src?

  • That’s right Felipe, at the time I recover the values edited by JS

  • you could use other events in the Image tag, have a look and see if you can contextualize https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image_events(v=vs.110). aspx

  • Thanks Thiago, I’ll take a look. In general what I looked for here the solution will be to apply a Hiddenfield. Brigadoaoo http://stackoverflow.com/questions/25507622/setting-asp-net-button-attributes-client-side-and-read-attribute-value-server-si

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.