微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

原文地址:https://www.jb51.cc/aspnet/250220.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐