Inner image and text of asp:LinkButton disappears after postback(asp:LinkButton 的内部图像和文本在回发后消失)
问题描述
我有一个链接按钮:
<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 被发送回浏览器),但是如果我点击页面上的另一个按钮(这使得一个完整的回发)LinkButtonPrint
将没有内部内容,它将像这样呈现:
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
中删除 LinkButtonPrint.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.net 链接按钮图像在回发后不可见
但那个也没有解决:(
EDIT
This is duplicate of
asp.net Link button image not visible after postback
but that one is not solved either :(
推荐答案
我找到了解决方案:
我不得不将 runat="server"
添加到 <img>
标签内的 <asp:LinkButton>
:
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:LinkButton 的内部图像和文本在回发后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:asp:LinkButton 的内部图像和文本在回发后消失


基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01