asp.net – 内部图像和文本的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处理程序,如下所示:

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

渲染的HTML是这样的:

<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将不会内容内容,将呈现如下:

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

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

在这里缺少什么?

编辑
这是重复的
asp.net Link button image not visible after postback.
但是一个没有解决

解决方法

这个问题现在已经被Microsoft知道了,他们已经在 Microsoft Connect issue 718810: LinkButton controls collection lost on postback发布了官方声明和解决方法.

微软的声明是:

Thank you for the Feedback. This seems like an oddity with the fact that the LinkButton control allows either direct text content via the Text property or in markup,or sub-controls via the Controls collection or markup. The workaround is to use a placeholder as the root content for the control and place the desired mixed content in there,e.g.

<asp:LinkButton runat="server">
    <asp:PlaceHolder runat="server">
        This is some text.</br>
        <asp:Label runat="server">This is a control</asp:Label>
    </asp:PlaceHolder>
</asp:LinkButton>

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....