Hi indradeo,
When you are clicking on Button your entire page reloading so that your Image URL value is destroying.
So the solution is that you need to set Image url value in HiddenField and call that HiddenField on jQuery Button click it will retain your Image url value on Button click.
Please refer below sample.
HTML
<img id="imgMVC" src="Images/MVC.png" alt="MVC Logo" width="200" />
<br />
<input type="hidden" id="hfImg" runat="server" />
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="Submit" />
<hr />
<img id="imgCopy" width="200" runat="server" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[Id*=btnSubmit]').on('click', function () {
var img = $('[id*=imgMVC]');
$('[id*=hfImg]').val(img.attr('src'));
});
});
</script>
Code
C#
protected void Submit(object sender, EventArgs e)
{
imgCopy.Attributes["src"] = hfImg.Value;
}
VB.Net
Protected Sub Submit(ByVal sender As Object, ByVal e As EventArgs)
imgCopy.Attributes("src") = hfImg.Value
End Sub
Screenshot