473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

C# .Net: button OnClick event not being recognized

Hello,

I have a C# .Net 2.0 project. Every single page with a button that contains an OnClick method receives a Compilation Error on run stating the definition for the OnClick method does not exist. Here is an example of one of the pages:

<asp:Button ID="cmdRunXMLValidation" runat="server" Text="Run XML Validation" OnClick="cmdRunXMLValidation_Click"></asp:Button>

back-end:

protected void cmdRunXMLValidation_Click(object sender, System.EventArgs e)
{
//stuff
}

and it recieves this error:
'ASP.xmlvalidationprojectsnew_xmlvalidmain_aspx' does not contain a definition for 'cmdRunXMLValidation_Click'

I have had this problem before when using a .NET 1.1 project because the OnClick events weren't properly defined in the InitializeComponent() method, but I was pretty sure I don't need to define such things in 2.0, is this correct? Any ideas?

Thanks,
Callie
Aug 29 '08 #1
7 7245
Plater
7,872 Expert 4TB
Do the tops of both the aspx and aspx.cs files have mathcing names and such?

For example
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ManagerAbilities.aspx.cs" Inherits="MangagerAbilities" %>
  2.  
And
Expand|Select|Wrap|Line Numbers
  1. public partial class MangagerAbilities : System.Web.UI.Page
  2.  
Aug 29 '08 #2
Yes they do:

<%@ Page Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true" CodeBehind="XmlValidMain.aspx.cs"
Inherits="PrintingEngine.XMLValidationProjectsNew. XmlValidMain" Title="Synet Media - XML Validate"%>

and

public partial class XmlValidMain : System.Web.UI.Page

Callie
Aug 29 '08 #3
Plater
7,872 Expert 4TB
I think even the inherits has to match
Aug 29 '08 #4
But the 'inherits' declaration is the correct namespace of the file. If I change it to just 'XmlValidMain' I get the following error:

Parser Error Message: Could not load type 'XmlValidMain'.

Source Error:
Line 1: <%@ Page Language="C#" MasterPageFile="~/MasterPages/Main.Master" AutoEventWireup="true" CodeBehind="XmlValidMain.aspx.cs"
Line 2: Inherits="XmlValidMain" Title="Synet Media - XML Validate"%>
Line 3:
This may be part of it: this project initially contained Page_Init and InitializeComponent() methods and I removed them and added the OnClick declarations to the button objects instead. Does anthing else need to be changed for that to work?
Aug 29 '08 #5
Plater
7,872 Expert 4TB
Is this a .net1.1 web application?
I've never had access to my page_init() and the InitializeComponent() functions in any of my .net2.0 web projects.
Aug 29 '08 #6
No it's a 2.0 application. Me either that's why I was surprised to see those methods in the code. I think possibly someone before me upgraded from 1.1 to 2.0 and that is why the methods existed.
Aug 29 '08 #7
Plater
7,872 Expert 4TB
Could you just re-make the file from scratch?
i.e. delete them and then re-add them and copy/paste the contents back in?
That works a lot more frequently then it should
Aug 29 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Dipin | last post by:
Hi All; I have this javascript which is adding a new button to the column in the row which is created dynamically, the innerhtml shows that the onclick event is correctly added but it never gets...
4
by: Daisy | last post by:
In my user control: <asp:Button id="btnLogin" runat="server" Text="Login"></asp:Button> And the code-behind: protected override void OnInit(EventArgs e) { btnLogin.EnableViewState = true;...
2
by: Sandeep | last post by:
Hi I want to write onclick event on a button(a web control) ,also i want to call a client side function on the click event how to write that how to differentiate between these two events ...
4
by: Chad | last post by:
I have a link (.ascx) and that generates an Add form on that page. The autopostback dropdown is within a "If Not IsPostBack Then" statement. The form that is created is all via static html in the...
1
by: Tim::.. | last post by:
Is there a way to fire an onClick JavaScript event on the next page to be loaded in ASP.NET??? I have 2 asp.net pages... page 1. With just a standard link to the next page. page 2. Has a...
2
by: Roger Cantillo | last post by:
Hi, In a webform, is it possible to change the OnClick event of a button at runtime? -- Axiom Software, Ltd. 400 Columbus Ave Valhalla, NY 10595 (914) 769-8800
3
by: Steven J. Smith | last post by:
I have an ASP.Net web page with a button that works as anticipated 95% of the time. I’ve had a few users report that clicking the button on their browser has no affect. This appears to be a...
2
by: moondaddy | last post by:
I have an asp.net 2.0 application and put a html button on a web page. I double clicked on the button and it crated the event handler for me and created the stub js function for it like this: ...
1
by: munkee | last post by:
A very simple question which I cant answer myself at the meoment due to epic tiredness. I have a combobox in my access 2003 database which is populated with the real names of users taken from a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.