473,385 Members | 1,712 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,385 software developers and data experts.

Visual Studio 2005 Adding Handlers

Hi,

Im fairly new to 2005 and I was wondering.

In 2003, when you add a button, it also adds and AddHandler statement within
the initialisation routine to wire up the handler to the event.

In VS 2005, I cant find this construct anywhere, not even in the designer.cs
in my WebProject application.

Any ideas how / where this is declared ?

Cheers
Oct 30 '07 #1
9 1147
Note also the OnClick property/attribute in the markup - i.e.

<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />

Marc
Oct 30 '07 #3
Thanks, I did know about the AutoWireup. Bu even if I specify False in the
page and or in the web.config, it still generates the wireup when compiled,
it seems that you cannot stop the autowireup in 2005 ( Although Im sure you
can ) I cant seem to, I want to be able to add the wireup code manually.

Any ideas ?
"Marc Gravell" <ma**********@gmail.comwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
auto wireup:

http://www.codeproject.com/aspnet/AutoEventWireup.asp

Marc

Oct 30 '07 #4
Ahhh. OK Gotcha, thats the new bit

If I wanted to add "Programatically" more events to the handler for a
button, for example in a calculator program, where would I do this as I dont
see the initialise component sub anymore. ?

Cheers

"Marc Gravell" <ma**********@gmail.comwrote in message
news:Ol**************@TK2MSFTNGP02.phx.gbl...
Note also the OnClick property/attribute in the markup - i.e.

<asp:Button ID="Button1" runat="server" Text="Button"
OnClick="Button1_Click" />

Marc

Oct 30 '07 #5
Has the markup got an OnClick="Something" entry? Try removing this;
then add your handlers through code and all should be well.

Marc
Oct 30 '07 #6
Well, if using auto-wireup, just declare a suitable Page_{YourEvent}
method - but IMO an easier option is to override (as below) the base
Page methods; the IDE helps you out as soon as you type "override",
plus it doesn't incur the (very small) overhead of event subscription
and delegate invokation. But my main point here is that it is easy to
get right as the IDE stubs everything automatically:

protected override void OnInit(EventArgs e){
base.OnInit(e);
// your code
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// etc
}

Marc
Oct 30 '07 #7
I did this, but the event does not seem to fire or at least the
Button1_Click is not being called.

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

{

protected void Page_Load(object sender, EventArgs e)

{

this.Button1.Click += new System.EventHandler(Button1_Click);

this.Button2.Click += new System.EventHandler(Button1_Click);

}

protected void Button1_Click(object sender, EventArgs e)

{

System.Web.UI.WebControls.Button senderButton;

senderButton = (System.Web.UI.WebControls.Button) sender;

this.TextBox1.Text = senderButton.ID;

}

}

"Marc Gravell" <ma**********@gmail.comwrote in message
news:eK**************@TK2MSFTNGP02.phx.gbl...
Has the markup got an OnClick="Something" entry? Try removing this; then
add your handlers through code and all should be well.

Marc

Oct 30 '07 #8
Excellent !

Thanks

"Just Me" <news.microsoft.comwrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
>I did this, but the event does not seem to fire or at least the
Button1_Click is not being called.

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

{

protected void Page_Load(object sender, EventArgs e)

{

this.Button1.Click += new System.EventHandler(Button1_Click);

this.Button2.Click += new System.EventHandler(Button1_Click);

}

protected void Button1_Click(object sender, EventArgs e)

{

System.Web.UI.WebControls.Button senderButton;

senderButton = (System.Web.UI.WebControls.Button) sender;

this.TextBox1.Text = senderButton.ID;

}

}

"Marc Gravell" <ma**********@gmail.comwrote in message
news:eK**************@TK2MSFTNGP02.phx.gbl...
>Has the markup got an OnClick="Something" entry? Try removing this; then
add your handlers through code and all should be well.

Marc


Oct 30 '07 #9
The following works, but I can't recall if this is the best place to
subscribe... I haven't been doing much ASP.NET lately, so can't
remember 100%

protected override void CreateChildControls()
{
base.CreateChildControls();
Button1.Click += Button1_Click;
}
Oct 30 '07 #10

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

Similar topics

30
by: Cowboy \(Gregory A. Beamer\) | last post by:
There seems to be a lot of confusion on the versions of Visual Studio 2005. My latest blog entry covers the different versions: Main URL:...
29
by: Cowboy \(Gregory A. Beamer\) | last post by:
There seems to be a lot of confusion on the versions of Visual Studio 2005. My latest blog entry covers the different versions: Main URL:...
2
by: Mark | last post by:
Hi everyone, I am having a tinker around with Visual Studio Professional 2005 and I am building a simple website: Now, in 1.1 the event handlers were declared in the code behind page and you...
8
by: WT | last post by:
Is it normal that Visual Studio sets the PreInit handler for a Page from the OnInit code ? No chance to fire it as OnPreInit is run befor OnInit. ??? CS
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.