ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Assign Image URL to Link Button in JavaScript<p>Hi <a class="username" rel="nauna"> nauna</a>,</p> <p>Please refer below sample.</p> <p><span style="text-decoration: underline;"><strong>HTML</strong></span></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34;&gt; function ShowHideDiv() { if (document.getElementById(&#39;&lt;%=myCheck1.ClientID%&gt;&#39;).checked == true) { document.getElementById(&#39;&lt;%=myCheck2.ClientID%&gt;&#39;).checked = false; document.getElementById(&#39;&lt;%=myCheck1.ClientID%&gt;&#39;).checked == true; document.getElementById(&#39;&lt;%=Image3.ClientID%&gt;&#39;).src = &#34;Desert.jpg&#34;; document.getElementById(&#39;hfValue&#39;).value = &#34;Desert.jpg&#34;; } } function ShowHideDiv1() { if (document.getElementById(&#39;&lt;%=myCheck2.ClientID%&gt;&#39;).checked == true) { document.getElementById(&#39;&lt;%=myCheck1.ClientID%&gt;&#39;).checked = false; document.getElementById(&#39;&lt;%=myCheck2.ClientID%&gt;&#39;).checked == true; var hvalue = document.getElementById(&#39;&lt;%=Image3.ClientID%&gt;&#39;).src = &#34;Desert.jpg&#34;; document.getElementById(&#39;hfValue&#39;).value = hvalue; } } &lt;/script&gt; &lt;div&gt; &lt;label class=&#34;switch pull-left&#34;&gt; &lt;input type=&#34;checkbox&#34; checked runat=&#34;server&#34; id=&#34;myCheck1&#34; onclick=&#34;ShowHideDiv()&#34; /&gt; &lt;span class=&#34;slider round&#34;&gt;&lt;/span&gt; &lt;/label&gt; &lt;h5&gt; Sort by business &lt;/h5&gt; &lt;label class=&#34;switch pull-left&#34;&gt; &lt;input type=&#34;checkbox&#34; runat=&#34;server&#34; id=&#34;myCheck2&#34; onclick=&#34;ShowHideDiv1(this)&#34; /&gt; &lt;span class=&#34;slider round&#34;&gt;&lt;/span&gt; &lt;/label&gt; Sort by name &lt;asp:LinkButton ID=&#34;LinkButton1&#34; runat=&#34;server&#34; CssClass=&#34;btn-xs btn btn-default pull-right&#34;&gt; &lt;asp:Image ID=&#34;Image3&#34; runat=&#34;server&#34; ImageUrl=&#34;Chrysanthemum.jpg&#34; Width=&#34;30px&#34; Height=&#34;32px&#34; /&gt; &lt;/asp:LinkButton&gt; &lt;asp:HiddenField ID=&#34;hfValue&#34; runat=&#34;server&#34; /&gt; &lt;/div&gt;</pre> <p><span style="text-decoration: underline;"><strong>Code</strong></span></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Page_Load(object sender, EventArgs e) { if (!string.IsNullOrEmpty(hfValue.Value)) { Image3.ImageUrl = hfValue.Value; } }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not String.IsNullOrEmpty(hfValue.Value) Then Image3.ImageUrl = hfValue.Value End If End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><img src="https://imgur.com/fLRq5r2.gif" alt="" width="245" height="227" /></p>https://www.aspforums.net:443/Threads/176081/Assign-Image-URL-to-Link-Button-in-JavaScript/https://www.aspforums.net:443/Threads/176081/Assign-Image-URL-to-Link-Button-in-JavaScript/Fri, 19 Oct 2018 05:04:54 GMT