asp:LinkBut​​ton 的内部图像和文本在回发后消失

编程入门 行业动态 更新时间:2024-10-26 16:31:21
本文介绍了asp:LinkBut​​ton 的内部图像和文本在回发后消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个链接按钮:

<asp:LinkButton ID="LinkButtonPrint" runat="server" OnClick="OnPrint_Click"> <img src="img/print-icon.png" alt="" /> <asp:Literal runat="server" Text="<%$ Resources:PrintPage %>" /> </asp:LinkButton>

在后面的代码中,我在 Page_Load 中添加了一个 onclick 处理程序,如下所示:

In code behind I add an onclick handler in Page_Load like this:

LinkButtonPrint.Attributes["onclick"] = "StartLoadTracking(this, '" + GetLocalResourceObject("Loading") + "')";

呈现的 HTML 是这样的:

The rendered HTML is like this:

<a href="javascript:__doPostBack('ctl00$LinkButtonPrint','')" id="ctl00_LinkButtonPrint" onclick="StartLoadTracking(this, 'Loading...');"> <img alt="" src="img/print-icon.png">Print page </a>

如果我点击这个按钮它工作正常(它会响应一个 PFD 文件,所以没有 HTML 被发送回浏览器),但是如果我点击页面上的另一个按钮(这使得一个完整的回发)LinkBut​​tonPrint 将没有内部内容,它将像这样呈现:

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 another button on the page (which makes a full postback) the LinkButtonPrint will not have the inner content, it will be rendered like this:

<a href="javascript:__doPostBack('ctl00$LinkButtonPrint','')" id="ctl00_LinkButtonPrint" onclick="StartLoadTracking(this, 'Loading...');"></a>

如果我从 Page_Load 中删除 LinkBut​​tonPrint.Attributes["onclick"] = ... 行,一切正常(除了我的 js 函数没有被调用,但是是正常的).

If I remove the LinkButtonPrint.Attributes["onclick"] = ... line from Page_Load everything works fine (except my js function is not called, but that is normal).

我在这里遗漏了什么?

编辑这是的副本asp 链接按钮图像在回发后不可见但那个也没有解决:(

EDIT This is duplicate of asp Link button image not visible after postback but that one is not solved either :(

推荐答案

我找到了解决方案:我不得不将 runat="server" 添加到 <img> 标签内的 <asp:LinkBut​​ton>:

I found the solution: I had to add runat="server" to the <img> tag inside the <asp:LinkButton>:

<img src="img/print-icon.png" alt="" runat="server" />

更多推荐

asp:LinkBut​​ton 的内部图像和文本在回发后消失

本文发布于:2023-10-12 20:48:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   文本   LinkBut   asp   回发后

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!