将 CSS 应用到 .NET ImageButton
我有以下 CSS,可以将其应用于 HTML 输入标记。
#headerSearch
{
width: 265px;
}
#headerSearch .text
{
width: 215px;
}
#headerSearch #searchButton
{
background: url(../images/searchButton.png) no-repeat 0 0;
width: 36px;
border: 1px solid #ccc;
margin: 0;
}
#headerSearch #searchButton:hover
{
background: url(../images/searchButton.png) no-repeat 0 -28px;
}
我应用它的 HTML...
<div id="headerSearch" class="float">
<input id="txtSearch" class="text left" type="text" />
<input id="searchButton" class="submit right" type="submit" value="" />
</div>
效果非常好。
但是,我想使用 ImageButton 控件而不是输入标记,因为我想要 ImageButton 的页面提交行为(当您单击它并引发单击事件等时发生),但我不确定如何进行关于将 CSS 与 ImageButton 混合使用。我尝试了类似的简单操作
<asp:ImageButton ID="ibtnSrch" runat="server" CssClass="searchBtn" onclick="ibtnSrch_Click" AlternateText="Search" />
,但发生的情况是图像在其上方的白色框中显示有一个红色 X(默认图像缺少图标)。
那么,更简洁地说,如何将优雅的 CSS 与 .NET ImageButton 混合在一起?
I have the following CSS that I can apply to an HTML input tag.
#headerSearch
{
width: 265px;
}
#headerSearch .text
{
width: 215px;
}
#headerSearch #searchButton
{
background: url(../images/searchButton.png) no-repeat 0 0;
width: 36px;
border: 1px solid #ccc;
margin: 0;
}
#headerSearch #searchButton:hover
{
background: url(../images/searchButton.png) no-repeat 0 -28px;
}
And the HTML to which I apply it...
<div id="headerSearch" class="float">
<input id="txtSearch" class="text left" type="text" />
<input id="searchButton" class="submit right" type="submit" value="" />
</div>
It works wonderfully.
However, I want to use an ImageButton control instead of the input tag because I want the page submit behavior of the ImageButton (which occurs when you click on it and click event is raised, etc.), but I am not sure how to go about mixing CSS with the ImageButton. I tried something simple like
<asp:ImageButton ID="ibtnSrch" runat="server" CssClass="searchBtn" onclick="ibtnSrch_Click" AlternateText="Search" />
but what occurs is the image displays with a red X in a white box (the default image is missing icon) over top of it.
So, more succinctly, how do I mix elegant CSS with the .NET ImageButton?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据示例代码,您已将
CssClass 设置为"searchBtn"
但没有.searchBtn
的 CSS >也许将其添加到您的 css 中
,
渲染为因为该控件是一个没有图像源的图像输入,这就是为什么你会得到一个红色的 x
based on the sample code you have set the
<asp:ImageButton />
CssClass to"searchBtn"
but there is no CSS for.searchBtn
perhaps add this to your css
an
<asp:ImageButton />
renders down to<input type="image" name="ibtnSrch" id="ibtnSrch" class="searchBtn" src="" alt="Search" style="border-width:0px;" />
since the control is an image input with no image source that is why you get a red x
如果您将
searchButton
样式更改为一个类,那么您只需使用您就可以将该按钮放在单独的 ValidationGroup 或设置
CausesValidation="false"
。如果您想将其全部保留在客户端并在 JavaScript 中重定向到搜索页面,但也想利用您在控件上设置的 ASP.NET 验证,则可以使用 客户端 ASP.NET 验证。
If you change your
searchButton
style to be a class, then you can just use an<asp:Button>
You can then put that button in a separate ValidationGroup or set
CausesValidation="false"
.If you want to keep it all client-side and do the redirect to the search page in JavaScript but also want to take advantage of the ASP.NET validation you've set up on your controls, you can use the client-side ASP.NET validation.
简而言之,我不会使用 asp 图像按钮。
我将使用您当前的 html 控件,然后添加一些 javascript 以在单击提交输入时单击隐藏的 asp:Button 控件。
我不太记得这是否是获取客户端 ID 的正确语法......
In short I would not use the asp image button.
I would use your current html controls and then add some javascript to click a hidden asp:Button control when your submit input is clicked.
I don't quite recall if that is the correct syntax to get the client id...