Note that there are some explanatory texts on larger screens.

plurals
  1. POInner image and text of asp:LinkButton disappears after postback
    primarykey
    data
    text
    <p>I have a link button:</p> <pre><code>&lt;asp:LinkButton ID="LinkButtonPrint" runat="server" OnClick="OnPrint_Click"&gt; &lt;img src="img/print-icon.png" alt="" /&gt; &lt;asp:Literal runat="server" Text="&lt;%$ Resources:PrintPage %&gt;" /&gt; &lt;/asp:LinkButton&gt; </code></pre> <p>In code behind I add an <code>onclick</code> handler in <code>Page_Load</code> like this:</p> <pre><code>LinkButtonPrint.Attributes["onclick"] = "StartLoadTracking(this, '" + GetLocalResourceObject("Loading") + "')"; </code></pre> <p>The rendered HTML is like this:</p> <pre><code>&lt;a href="javascript:__doPostBack('ctl00$LinkButtonPrint','')" id="ctl00_LinkButtonPrint" onclick="StartLoadTracking(this, 'Loading...');"&gt; &lt;img alt="" src="img/print-icon.png"&gt;Print page &lt;/a&gt; </code></pre> <p>If I click this button it is working OK (it will respond with a PFD file so no HTML is sent back to the browser), but if I click <strong>another</strong> button on the page (which makes a full postback) the <code>LinkButtonPrint</code> will not have the inner content, it will be rendered like this:</p> <pre><code>&lt;a href="javascript:__doPostBack('ctl00$LinkButtonPrint','')" id="ctl00_LinkButtonPrint" onclick="StartLoadTracking(this, 'Loading...');"&gt;&lt;/a&gt; </code></pre> <p>If I remove the <code>LinkButtonPrint.Attributes["onclick"] = ...</code> line from <code>Page_Load</code> everything works fine (except my js function is not called, but that is normal).</p> <p>What am I missing here?</p> <p><strong>EDIT</strong><br> This is duplicate of<br> <a href="https://stackoverflow.com/questions/2131510">asp.net Link button image not visible after postback</a><br> but that one is not solved either :(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload