Inner image and text of asp:LinkButton disappears after postback(asp:LinkButton 的内部图像和文本在回发后消失)
问题描述
我有一个链接按钮:
<asp:LinkButton ID="LinkButtonPrint" runat="server" OnClick="OnPrint_Click">
<img src="aW1nL3ByaW50LWljb24ucG5n" alt="IiAvJmd0OwogICAgICZsdDthc3A6TGl0ZXJhbCBydW5hdD0="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="IiBzcmM9"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="aW1nL3ByaW50LWljb24ucG5n" alt="IiBydW5hdD0="server" />
这篇关于asp:LinkButton 的内部图像和文本在回发后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:asp:LinkButton 的内部图像和文本在回发后消失


- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01