473,396 Members | 2,037 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,396 software developers and data experts.

Button OnClick event not firing

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;
btnLogin.Click += new EventHandler(btnLogin_Click);
base.OnInit(e);
}

public void btnLogin_Click(object sender, EventArgs e)
{
throw new Exception("Worked!");
}
I tried enabling viewstate (I was told events don't work without it),
because I've set it to default to false in web.config, but still, it never
fires. How do I debug something like this? :-\

It's posting back fine, just never hitting the code in the Click method

--
Daisy The Cow
Nov 15 '05 #1
4 35153
I honestly have to admit being a bit of an amateur with ASP.NET, but my
undertstading is that ViewState has nothing to do with events. ViewState
simply records previous states of controls so that during postback the
controls will maintain their state (for example, the contents of a listbox
does not have to be repopulated at postback if ViewState is enabled).

That said, I'm not sure what could be causing your button not to work.

Pete

"Daisy" <da***@nospam.oops> wrote in message
news:bu**********@linux01.dannytuppeny.com...
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;
btnLogin.Click += new EventHandler(btnLogin_Click);
base.OnInit(e);
}

public void btnLogin_Click(object sender, EventArgs e)
{
throw new Exception("Worked!");
}
I tried enabling viewstate (I was told events don't work without it),
because I've set it to default to false in web.config, but still, it never
fires. How do I debug something like this? :-\

It's posting back fine, just never hitting the code in the Click method

--
Daisy The Cow

Nov 15 '05 #2
"Daisy" <da***@nospam.oops> wrote in message
news:bu**********@linux01.dannytuppeny.com...
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;
btnLogin.Click += new EventHandler(btnLogin_Click);
base.OnInit(e);
}

public void btnLogin_Click(object sender, EventArgs e)
{
throw new Exception("Worked!");
}
I tried enabling viewstate (I was told events don't work without it),
because I've set it to default to false in web.config, but still, it never
fires. How do I debug something like this? :-\

It's posting back fine, just never hitting the code in the Click method


Oh, and the asp:TextBox's that are next to it aren't holding their values
across postbacks, so whatever is causing that, is probably the same as
what's causing my events not to fire? :-\
--
Daisy The Cow
Nov 15 '05 #3
"Pete Davis" <pd******@hotmail.com> wrote in message
news:20******************************@news.meganet news.com...
I honestly have to admit being a bit of an amateur with ASP.NET, but my
undertstading is that ViewState has nothing to do with events. ViewState
simply records previous states of controls so that during postback the
controls will maintain their state (for example, the contents of a listbox
does not have to be repopulated at postback if ViewState is enabled).


I didn't think so too, I'm just clutching at straws :O(
--
Daisy The Cow
Nov 15 '05 #4
"Daisy" <da***@nospam.oops> wrote in message
news:bu**********@linux01.dannytuppeny.com...
<snip>

Solved it. The control containing the button was inside Head.ascx, and I
forgot that that one's loaded with LoadControl by the derived page class,
and was done in PreRender. Moved it to OnInit and all works fine :)
--
Daisy The Cow
Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
5
by: Ben Fidge | last post by:
I've got a problem where some buttons placed on a user control are only firing their OnClick events when the user clicks on them for the second time. I've got the situation where some common...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
7
by: CharlesA | last post by:
Hi folks, first off, I'm using .Net framework 1.1 with ASP.net and C# I'm trying to do something very simple...but I can't figure it out I have an <asp:button runat="server"> in the test...
2
by: showens | last post by:
I have a table that has rows appended dynamically, based on the item selected from a dropdownlist. The rows have a number of cells, one with a literal control using the text of the dropdownlist,...
7
by: rsaffy | last post by:
I am having trouble with my dynamically created button's event handling. I read that the buttons need to be recreated on every trip to the server, but how exactly do you do that when the datagrid...
8
by: SAL | last post by:
Hello, I have a button on a webform that has an OnClick event defined as such: <asp:Button ID="btnSearchByName" runat="server" Text="Search By Name" OnClick="btnSearchByName_Click" Width="152px"...
3
by: Jay | last post by:
I am on the 2.0 framework and have run the c:\windows\microsoft.net \framework\v1.1.4322\aspnet_regiis.exe -c and had no success. About half of the buttons on my webforms are firing and the other...
0
by: =?Utf-8?B?Sm9obiBIYXJ0ZQ==?= | last post by:
Hi, In the code behind of my ASP.net web page I have code written that is dynamically creating a button. Here is a sample of how I define it. //Define Variable Button btnNext; public void...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.