OnClick vs InitializeComponent()

M

Mikael Janers

Hi!

When you want a serverside event on for example an asp:ImageButton... Whats
the difference between using OnClick="..." and binding the event in the
InitializeComponent() method ?
 
T

Teemu Keiski

The other (OnClick="handler") is a way to specify it declaratively, whereas
in code-behind (InitializeComponent or somewhere else before the events is
raised) it is a dynamic one. From functionality standpoint no difference,
but from application design yes as the latter is a way to hide the
implementation from the UI.
 
M

Mikael Janers

Okay thanks!, but I dont buy that the InitializeComponent would be any
better at hiding the implementation... You are still bound by the components
id in the aspx file ?. To me both methods are equaly sensitive if someone
messes with the aspx file. Either you are bound by the ID or by the OnClick
?
 
T

Teemu Keiski

It's not necessarily security caution, but logical caution say to improve
reusability, readability and structure of the code. Basically yes, ID or
attribute is the way (because of code-behind mechanism where dynamic page
class i.e aspx class inherits from the code-behind class so members must
match).
 
M

Mikael Janers

Oki, thanks very much for the feedback!

Teemu Keiski said:
It's not necessarily security caution, but logical caution say to improve
reusability, readability and structure of the code. Basically yes, ID or
attribute is the way (because of code-behind mechanism where dynamic page
class i.e aspx class inherits from the code-behind class so members must
match).

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


events
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top