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 的内部图像和文本在回发后消失
基础教程推荐
- 如果条件可以为空 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 将数据集转换为列表 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
