Environment: Microsoft Visual Studio 2019 Community, ASP.NET v4.8 web application project using VB.NET
Problem: I have an asp imagebutton which is used to indicate a status by changing the image each time it is clicked (red-amber-green-red). This is done using javascript:
btn.src = newImage;
This works fine. The imageurl is accessed using src in the html but the image is initially set in the code behind databind by setting the imagebutton.imageurl:
btn.ImageUrl = initialImage
On a postback (a save) I want to find the status by looking at the current imageurl.
Dim btn As ImageButton = CType(mainGrid.Rows(i).FindControl("btn"), ImageButton))
someval = btn.imageurl
The problem is that imageurl shows the value initially set, not the changed value. This weirdness seems to point to a bug in my code somewhere as obviously the imagebutton variable in the save code behind knows nothing about the imagebutton variable in the databind code behind.
Can someone confirm that imageurl in the postback should in fact match the changed src in the html?
Edit: I should say that I don't want to use server-side processing each time they click the imagebutton. I can make this work using a command argument BUT that leads to a database write every time they click. There are a dozen or so buttons on each row so I think that would be pretty slow in production.
The answer, provided by Albert D. Kallal, is that imagebuttons don't pass any changed attributes back to the code behind. Possible solutions are to 1) use an update panel, 2) change a paired hidden field at the same time (of a type that does pass the change back) or 3) use ajax to update the db after the change. I used option 3.