内图像和ASP的文字:LinkButton的回传后消失 [英] Inner image and text of asp:LinkButton disappears after postback
问题描述
结果
我有一个链接按钮:
I have a link button:
<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>
在code后面,我添加一个的onclick
处理程序的Page_Load
是这样的:
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 :(
推荐答案
我找到了解决办法:结果
我不得不添加 =服务器
到&LT; IMG&GT;
里的标签 &LT; ASP:LinkButton的&GT;
:
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的回传后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!