ASP.NET/HTML: HTML button's onClick property inside ASP.NET (.cs) ASP.NET/HTML: HTML button's onClick property inside ASP.NET (.cs) asp.net asp.net

ASP.NET/HTML: HTML button's onClick property inside ASP.NET (.cs)


You can do that on any server control and this button is made a server control by defining "runat=server". The problem is probably in your definition of the event:

<button ... runat="server" ... onServerClick="btnLogin_Click" />

You don't need "();" there...

Apart from that can you explain why you don't use the <asp:Button> here because I don't really see a problem with that...


You'll want to use the onServerClick. There's an example of how to do that on MSDN:

<button id="Button1" OnServerClick="Button1_OnClick" runat="server">    Click me!</button>protected void Button1_OnClick(object Source, EventArgs e) {    // secret codes go here}


btnLogin.Click += new EventHandler( btnLogin_Click );

will assign the btnLogin_Click event handler to the button's Click event.

however, I would point out that assigning a handler in the markup of the aspx page does not "expose your codes", as the HTML rendered down to the client doesn't have any of that information in it.