473,396 Members | 2,011 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.

wiring up html attribute declared event handlers

Hi,
I have a UserControl derived class:

<ns:votingbutton runat="server" id="btn1" onclick="votingbuttonclick" />

My question is, what code do I need in place in the codebehind for this to
be wired up? All the examples I've seen wire up the event programatically,
thus making this declarative attribute irrelevant. e.g.

btn1.click += new EventHandler(this.votingbuttonclick);

I've been looking at reflection and the control's Attribute collection, but
this looks awfully messy? I've tried using reflector to reverse engineer how
the stock webcontrols do it, but I just can't see it. I figure an attribute
hint is needed on an onclick property perhaps, but I can't find anything
that'll do the job?

Any hints?

- Oisin

Nov 17 '05 #1
7 3246
Hi Natty,

You misunderstand or misread my question. If you read my first post
correctly, you'll see that I'm referring to a UserControl derived control.
It is a server-side user-defined .ascx control, declared in an aspx page
like so:

<ns:mycontrol runat="server" onclick="myhandler" id="myctrl1"/>

much like the vanilla ASP control:

<asp:linkbutton runat="server" onclick="clickhandler" text="text"
id="lnkbtn1"/>

I want to know how to tie up the EventHandler delegate to a method called
"myhandler" in a page containing my custom control _without_ having to
programmatically do it via:

myctrl1.click += new EventHandler(myhandler);

When you add a linkbutton, you do not have to do it when you declare it via
the "onclick" attribute.

This has _nothing_ to do with client side script or postbacks at all.

- Oisin
"Natty Gur" <na***@dao2com.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

onclick="votingbuttonclick" will generate a call to client side script
with that name and it won't cause any call to the server. if you want
event to occur on the server side you need to generate a postback to the
server with the correct data in the __EVENTTARGET and __EVENTARGUMENT
fields.

Nov 17 '05 #2
Hi Natty,

You misunderstand or misread my question. If you read my first post
correctly, you'll see that I'm referring to a UserControl derived control.
It is a server-side user-defined .ascx control, declared in an aspx page
like so:

<ns:mycontrol runat="server" onclick="myhandler" id="myctrl1"/>

much like the vanilla ASP control:

<asp:linkbutton runat="server" onclick="clickhandler" text="text"
id="lnkbtn1"/>

I want to know how to tie up the EventHandler delegate to a method called
"myhandler" in a page containing my custom control _without_ having to
programmatically do it via:

myctrl1.click += new EventHandler(myhandler);

When you add a linkbutton, you do not have to do it when you declare it via
the "onclick" attribute.

This has _nothing_ to do with client side script or postbacks at all.

- Oisin
"Natty Gur" <na***@dao2com.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

onclick="votingbuttonclick" will generate a call to client side script
with that name and it won't cause any call to the server. if you want
event to occur on the server side you need to generate a postback to the
server with the correct data in the __EVENTTARGET and __EVENTARGUMENT
fields.

Nov 17 '05 #3
Hi Natty,
You still don't get it. I _know_ a delegate is needed. It can't work without
it. Please read my post again. I'll try to make it really simple for you, as
perhaps English is not your first language.

Look at this declaration for an asp:linkbutton

<asp:linkbutton runat="server" onclick="myhandler" id="btn1" />
^^^^^^^^^^^^^^^^^^^

The sgml attribute "onclick" is specifying a method to handle the click
event. If you check out the codebehind for this page, you'll see that there
is NO code to tie the delegate to the eventhandler. It just works. It is
added at run-time, not compile-time. The only thing the IDE will add is a
variable reference, e.g. "protected System.Web.UI.WebControls.LinkButton
btn1;".

Think about it for a second. If I added:

btn1.click += new EventHandler(this.myhandler)

to my codebehind page, why would I need 'onclick="myhandler"' on the
declaration? Yes, that's right -- I wouldn't need it. Understand now? I was
asking if anyone knew the [Attribute] or suitable reflection code to use to
automatically wireup sgml attribute eventhandlers.

Agh!! :-)

- Oisin




"Natty Gur" <na***@dao2com.com> wrote in message
news:eG*************@TK2MSFTNGP11.phx.gbl...
Hi,

Sorry about my misunderstanding.

Any way you can't do it without using EventHandler. Every event that
needs to be handling must use it in order to attach function to the
event. Even the linkbutton click event uses it. You can see it in
InitializeComponent function. The only different is that VS embed the
code for you.

private void InitializeComponent()
{
this.LinkButton1.Click += new
System.EventHandler(this.LinkButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #4
Hi Natty,
You still don't get it. I _know_ a delegate is needed. It can't work without
it. Please read my post again. I'll try to make it really simple for you, as
perhaps English is not your first language.

Look at this declaration for an asp:linkbutton

<asp:linkbutton runat="server" onclick="myhandler" id="btn1" />
^^^^^^^^^^^^^^^^^^^

The sgml attribute "onclick" is specifying a method to handle the click
event. If you check out the codebehind for this page, you'll see that there
is NO code to tie the delegate to the eventhandler. It just works. It is
added at run-time, not compile-time. The only thing the IDE will add is a
variable reference, e.g. "protected System.Web.UI.WebControls.LinkButton
btn1;".

Think about it for a second. If I added:

btn1.click += new EventHandler(this.myhandler)

to my codebehind page, why would I need 'onclick="myhandler"' on the
declaration? Yes, that's right -- I wouldn't need it. Understand now? I was
asking if anyone knew the [Attribute] or suitable reflection code to use to
automatically wireup sgml attribute eventhandlers.

Agh!! :-)

- Oisin




"Natty Gur" <na***@dao2com.com> wrote in message
news:eG*************@TK2MSFTNGP11.phx.gbl...
Hi,

Sorry about my misunderstanding.

Any way you can't do it without using EventHandler. Every event that
needs to be handling must use it in order to attach function to the
event. Even the linkbutton click event uses it. You can see it in
InitializeComponent function. The only different is that VS embed the
code for you.

private void InitializeComponent()
{
this.LinkButton1.Click += new
System.EventHandler(this.LinkButton1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 17 '05 #5
Declarative Syntax for Event Wiring
ASP.NET pages provide a declarative syntax for wiring server-side event
handlers on the control's tag:

<asp:Button id="button1" OnClick="button1_Click" Text="Submit"
runat="server" />

This syntax provides an intuitive model for page developers because it
is similar to the syntax for binding a client-side event handler on an
HTML tag (onmouse*over="client-side script function name").

When the page parser parses the .aspx file (as we described in "From
Text to Controls" in Chapter 2), it transforms the declarative syntax
into code that binds an event handler to an event via an event delegate
instance:

button1.Click += new EventHandler(this.button1_Click);
Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #6
Declarative Syntax for Event Wiring
ASP.NET pages provide a declarative syntax for wiring server-side event
handlers on the control's tag:

<asp:Button id="button1" OnClick="button1_Click" Text="Submit"
runat="server" />

This syntax provides an intuitive model for page developers because it
is similar to the syntax for binding a client-side event handler on an
HTML tag (onmouse*over="client-side script function name").

When the page parser parses the .aspx file (as we described in "From
Text to Controls" in Chapter 2), it transforms the declarative syntax
into code that binds an event handler to an event via an event delegate
instance:

button1.Click += new EventHandler(this.button1_Click);
Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #7
gokkor
1
Yeah, i know it's quite late to answer but here it is :

http://msdn.microsoft.com/library/de...ientsidesc.asp


Hi Natty,


You still don't get it. I _know_ a delegate is needed. It can't work without
it. Please read my post again. I'll try to make it really simple for you, as
perhaps English is not your first language.

Look at this declaration for an asp:linkbutton

<asp:linkbutton runat="server" onclick="myhandler" id="btn1" />
^^^^^^^^^^^^^^^^^^^

The sgml attribute "onclick" is specifying a method to handle the click
event. If you check out the codebehind for this page, you'll see that there
is NO code to tie the delegate to the eventhandler. It just works. It is
added at run-time, not compile-time. The only thing the IDE will add is a
variable reference, e.g. "protected System.Web.UI.WebControls.LinkButton
btn1;".

Think about it for a second. If I added:

btn1.click += new EventHandler(this.myhandler)

to my codebehind page, why would I need 'onclick="myhandler"' on the
declaration? Yes, that's right -- I wouldn't need it. Understand now? I was
asking if anyone knew the [Attribute] or suitable reflection code to use to
automatically wireup sgml attribute eventhandlers.

Agh!! :-)

- Oisin














"Natty Gur" <natty@dao2com.com> wrote in message
news:eGoo$aoSDHA.940@TK2MSFTNGP11.phx.gbl...[color=blue]
> Hi,
>
> Sorry about my misunderstanding.
>
> Any way you can't do it without using EventHandler. Every event that
> needs to be handling must use it in order to attach function to the
> event. Even the linkbutton click event uses it. You can see it in
> InitializeComponent function. The only different is that VS embed the
> code for you.
>
> private void InitializeComponent()
> {
> this.LinkButton1.Click += new
> System.EventHandler(this.LinkButton1_Click);
> this.Load += new System.EventHandler(this.Page_Load);
>
> }
>
> Natty Gur, CTO
> Dao2Com Ltd.
> 28th Baruch Hirsch st. Bnei-Brak
> Israel , 51114
>
> Phone Numbers:
> Office: +972-(0)3-5786668
> Fax: +972-(0)3-5703475
> Mobile: +972-(0)58-888377
>
> Know the overall picture
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it![/color]
Jun 14 '06 #8

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

Similar topics

1
by: Scott M | last post by:
I'm building a smart client application based off of the example that is posted on windowsforms.com (and shown on the .NET show). A windows form calls a webservice that itterates through a...
0
by: Plumer | last post by:
A warm, south pacific good morning to everyone I posted this message on one of the other MSDN newsgroups (Messaging & Collaboration) and realised later that perhaps it wasn't the best choice. If I...
0
by: Oisin Grehan | last post by:
Hi, I have a UserControl derived class: <ns:votingbutton runat="server" id="btn1" onclick="votingbuttonclick" /> My question is, what code do I need in place in the codebehind for this to...
2
by: Nathan Sokalski | last post by:
I would like to access variables and functions that I declare in the Global.asax.vb file. However, I am having trouble doing that. What does the declaration have to look like in the Global.asax.vb...
4
by: Jordan | last post by:
I need to dynamically add an ImageButton control to a user control and and do some server-side processing when the user clicks it. While I the ImageButton is added to the user control at runtime,...
2
by: Crispin Horsfield | last post by:
It's not useful to serialize events in a class that can be serialized so in C# you can use the 'field' attribute to mark events as 'NonSerializable'.This is not available in VB. Does anyone know...
5
by: Samuel R. Neff | last post by:
Is there a way to add the NonSerialized attribute to the "Event" fields that the VB.NET compiler creates when you declare an event? I have a class that we use with binary serialization and we...
1
by: bill | last post by:
I'm using VS2005. I am dynamically adding a Textbox control to a Placeholder control in the page_load event of the form, but the event handler isn't firing. What am I doing wrong? Thanks...
1
by: spoonybard | last post by:
Hi Everyone, Recently, when I was trying to wire up an event for a GridView inside an AJAX Accordion, I was doing the wiring up in the code behind. The event never fired. When I moved that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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,...
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.