asp:button onclick event is not working...
why is it so???

Dani AI

Generated

: an asp:Button is an ASP.NET Web Forms server control, not a Classic ASP element — was correct on that point. As suggested, the exact markup and code-behind are needed to diagnose, but the following checklist and minimal example cover the usual causes when an OnClick handler does not fire.

Minimal working pattern:

<%@ Page Language="C#" AutoEventWireup="true" Inherits="MyPage" %>

<form id="form1" runat="server">
  <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</form>
protected void btnSubmit_Click(object sender, EventArgs e)
{
  // server-side logic
}

Quick troubleshooting checklist

  • Ensure the page is served as an ASP.NET page (.aspx) from IIS / the development server (file:// will not run server events).
  • Confirm the control is inside a <form runat="server">. Server events require a server form.
  • Verify the OnClick name matches the code-behind method signature and the @Page Inherits/class name matches the compiled class.
  • If AutoEventWireup="false", either set it to true or wire the handler in Page_Init.
  • If inside a MasterPage, ensure the master contains the server form (content pages must not add another server form).
  • Validators can block postback — set CausesValidation="false" temporarily to test.
  • Client-side scripts returning false (e.g., OnClientClick="return false;") prevent postback.
  • For controls in data templates (GridView/Repeater), use CommandName/OnCommand or the appropriate row/item events.
  • Rebuild the project and verify the designer file contains the control declaration.

For deeper reading on the control event and page lifecycle see Microsoft docs: Button.OnClick and .

Recommended Answers

All 2 Replies

You need to post your code if you want help with it.

Isn't it an ASP.net feature?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.