Is it possible to replace asp: button with HTML element

I use asp forms and want to know if standard buttons can be replaced with HTML elements that are styled using CSS.

My login page uses a standard button

<asp:Button ID="LoginButton" runat="server" Text="Login" 
    onclick="LoginButton_Click" />

linked to code (C #) that performs login validation.

I saw some good buttons implemented using an HTML element <button>and styled using CSS, which can have features like images and scrolling. The basic HTML looks like this:

<button type="submit" class="positive" onclick ="...">
    <img src="/icons/tick.png" alt=""/> 
    Login
</button>

I saw another question discussing the Difference between an asp: button and html button , so I understand that the element is <button>not a replacement, but I'd like to know if it is possible to replace asp:buttonand still call LoginButton_ClickC # code ?

EDIT:
ASP, javascript , .

, , , :

2: XIII LinkButton asp , , , #

<asp:LinkButton ID="LoginBtn" CssClass="button positive"
        OnClick="LoginButton_Click" runat="server">
    <img src="/icons/tick.png" alt=""/> 
    Login
</asp:LinkButton>

Javascript ( ), , ; asp:loginview , , javascript, , .

jwiscarson, , , , , <button> <asp:button>

+5
5

:

asp: - LoginButton_Click #?

- . :

<button type="submit" id="submit" class="positive" runat="server">Submit</button>

, , onclick, onserverclick. - :

protected override OnInit(EventArgs e)
{
    submit.ServerClick += new EventHandler(submit_ServerClick);
}

, , - CSS, .

+2

CSS cssClass <asp:Button/>. runat="server" onserverclick="LoginButton_Click" <button/>.

+1

LinkButton , CSS. . .

, CssClass

+1

HTML, , , __doPostBack() . Asp.Net HTML , , .

0

As already posted here, you can create HTML code created by yours asp:button, or use another asp control. Your asp:buttonwill be displayed as <input type="submit">with as much limited CSS options as possible than the tag <button>.

From some googling, I think you can get a tag <button>, but it looks like a non-trivial exercise, see How can I use a button tag with ASP.NET?

0
source

All Articles