ASP.net c# button click
Given:
<button runat="server" id="btnNext">Next ></button>
I need in my code behind the have the onclick event, but the onclick event in this case refers to clientonclick, I have to use the button HTML tag not ASP:button because ASP:Button renders as input which doesn't work with my CSS....
Any ideas?
For everyone saying change my CSS, here it is:
input[type=button], button {
font-family: arial, sans-serif;
font-size: 12px;
font-weight: bold;
margin: 0px;
padding: 5px 20px 5px 20px;
outline-width: 0;
border: 1px solid #000;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5);
-moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.5),
inset 0px 1px 0px rgba(255, 255, 255, 0.5);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5),
inset 0px 1px 0px rgba(255, 255, 255, 0.5);
-webkit-transition: background-color 0.2s ease-in-out,
color 0.2s ease-in-out,
-webkit-box-shadow 0.2s ease-in-out;
-moz-transition: background-color 0.2s ease-in-out,
color 0.2s ease-in-out,
-moz-box-shadow 0.2s ease-in-out;
-o-transition: background-color 0.2s ease-in-out,
color 0.2s ease-in-out,
box-shadow 0.2s ease-in-out;
background-image: -webkit-gradient(linear, left top, left bottom,
color-stop(0.0, rgba(255, 255, 255, 0.8)),
color-stop(0.01, rgba(255, 255, 255, 0.6)),
color-stop(0.4, rgba(255, 255, 255, 0.3)),
color-stop(0.4, rgba(255, 255, 255, 0.2)),
color-stop(1.0, rgba(255, 255, 255, 0.0)));
background-image: -moz-linear-gradient(top,
开发者_如何转开发 rgba(255, 255, 255, 0.6) 0%,
rgba(255, 255, 255, 0.3) 40%,
rgba(255, 255, 255, 0.2) 40%,
rgba(255, 255, 255, 0.0) 100%);
background-color: #444;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 0px -1px 0px;
}
input[type=button]:hover, input[type=button]:focus, button:hover, button:focus {
-webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.9);
-moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.9),
inset 0px 1px 0px rgba(255, 255, 255, 0.5);
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.9),
inset 0px 1px 0px rgba(255, 255, 255, 0.5);
background-color: #666;
color: #fff;
}
input[type=button]:active, button:active {
background-color: #222;
color: #ccc;
-webkit-transition-duration: 0.0s;
-moz-transition-duration: 0.0s;
-o-transition-duration: 0.0s;
}
If I assign this to an input it doesn't show all the effects.
Change your CSS - the problem isn't with asp.net but its with your stylesheet. Its really not that hard to stick 'input' after 'button' in your stylesheet
The <button>
element will be translated into an HtmlButton instance in your code-behind. That class exposes a server-side ServerClick event that you can use for your purposes:
<button runat="server" id="btnNext"
OnServerClick="btnNext_Click">Next ></button>
protected void btnNext_Click(object sender, EventArgs e)
{
// Handle the click event...
}
精彩评论