[英]html button type and commandname in asp.net
我试图将命令名分配给html按钮,但是显然不能很好地工作。 这是我要实现的目标:
<button type="submit" class="btn btn-info right" CommandName="Login" runat="server" id="loginBtn"><span class="icon16 icomoon-icon-enter white"></span> Login</button>
<asp:Button ID="btnLogin" CommandName="Login" runat="server" CssClass="btn btn-info right" Text="Login" />
由于某种原因,样式无法在asp按钮上使用,但对于html按钮却可以使用。 现在,我想以某种方式将commandname属性分配给html按钮(如果可能)。 你们认为那可行吗? 每个评论表示赞赏。 在此先感谢Laziale
CommandName
仅可用于按钮服务器控制; 不在html按钮中。
但是,您可以使用LinkButton
并以所需的方式对其进行样式设置。
<asp:LinkButton ID="btnLogin" class="button" runat="server"
CommandName="Login"><span>Login</span></asp:LinkButton>
.button
{
background: transparent url('/Images/ButtonLeft.gif') no-repeat top left;
display: block;
float: left;
line-height: 11px; /* 21px (Button Background) = 5px (padding-top) + 11px (font-size) + 5px(padding-bottom) */
height: 21px; /* Button Background Height */
padding-left: 9px;
text-decoration: none;
font-weight: bold;
color: white;
font-size: 11px;
}
a:link.button, a:visited.button, a:active.button
{
color: white;
text-decoration: none;
margin-right: 10px;
}
a.button:hover
{
background-position: bottom left;
}
a.button span, a.button span
{
background: transparent url('/Images/ButtonRight.gif') no-repeat top right;
display: block;
padding: 5px 9px 5px 0; /*Set 9px below to match value of 'padding-left' value above*/
}
a.button:hover span
{
background-position: bottom right;
color: white;
}
我用谷歌找到了这个问题的答案。 但是,由于我已经找到了更完整的答案,因此即使这个问题比较老,我也会回答这个问题(以防其他Google员工找到它)。
在asp.net中,可以使用DataControlCommands类来实现以下功能:
意思是 :
<asp:LinkButton runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" />
除其他事项外。
在System.Web.UI.WebControls(msdn.microsoft.com)的库条目中
是的,您可以只放入html并使其正常工作-但是,如果您要构建类似动态实体网站(等)的东西,那么花一些时间来学习asp.net本身是如何做到的(imo)是值得的。
更好的方法是将HiddenField放在htmlbutton中,然后再找到子级
<button runat="server"
ClientIDMode="Static"
class="btn btn-success"
ID="button_recalculate"
OnServerClick="button_recalculate_OnClick"
>
<asp:HiddenField runat="server" ID="hidden" Value=<%#Eval("ID") %>/>
Voir
</button>
服务器
try
{
var type = (HtmlButton) sender;
var child = type.FindControl("hidden");
var id = ((HiddenField) child).Value.TransformToInt();
SendValueToServer(id);
}
catch (Exception)
{
//
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.