加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 内部图像和文本的asp:LinkBut??ton在回发后消失

发布时间:2020-12-15 23:19:20 所属栏目:asp.Net 来源:网络整理
导读:我有一个链接按钮: 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中添
我有一个链接按钮:
<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读