OnClick vs InitializeComponent()

Discussion in 'ASP .Net Web Controls' started by Mikael Janers, Nov 24, 2003.

  1. 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 ?
    Mikael Janers, Nov 24, 2003
    #1
    1. Advertising

  2. Mikael Janers

    Teemu Keiski Guest

    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.

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

    "Mikael Janers" <nospam> wrote in message
    news:...
    > 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 ?
    >
    >
    Teemu Keiski, Nov 25, 2003
    #2
    1. Advertising

  3. 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
    ?

    "Teemu Keiski" <> wrote in message
    news:...
    > 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.
    >
    > --
    > Teemu Keiski
    > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > ASP.NET Forum Moderator, AspAlliance Columnist
    >
    > "Mikael Janers" <nospam> wrote in message
    > news:...
    > > 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 ?
    > >
    > >

    >
    >
    Mikael Janers, Nov 25, 2003
    #3
  4. Mikael Janers

    Teemu Keiski Guest

    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


    "Mikael Janers" <nospam> wrote in message
    news:...
    > 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
    > ?
    >
    > "Teemu Keiski" <> wrote in message
    > news:...
    > > 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.
    > >
    > > --
    > > Teemu Keiski
    > > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > > ASP.NET Forum Moderator, AspAlliance Columnist
    > >
    > > "Mikael Janers" <nospam> wrote in message
    > > news:...
    > > > 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 ?
    > > >
    > > >

    > >
    > >

    >
    >
    Teemu Keiski, Nov 26, 2003
    #4
  5. Oki, thanks very much for the feedback!

    "Teemu Keiski" <> wrote in message
    news:...
    > 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
    >
    >
    > "Mikael Janers" <nospam> wrote in message
    > news:...
    > > 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
    > > ?
    > >
    > > "Teemu Keiski" <> wrote in message
    > > news:...
    > > > 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.
    > > >
    > > > --
    > > > Teemu Keiski
    > > > MCP, Microsoft MVP (ASP.NET), AspInsiders member
    > > > ASP.NET Forum Moderator, AspAlliance Columnist
    > > >
    > > > "Mikael Janers" <nospam> wrote in message
    > > > news:...
    > > > > 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 ?
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Mikael Janers, Nov 26, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack

    InitializeComponent error

    Jack, Nov 19, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    330
  2. enantiomer

    InitializeComponent versus page_load

    enantiomer, Feb 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,717
    Natty Gur
    Feb 22, 2004
  3. David
    Replies:
    1
    Views:
    325
    Mike Smith
    Jul 12, 2004
  4. kw
    Replies:
    3
    Views:
    3,804
    Scott Allen
    Jul 14, 2004
  5. Winshent
    Replies:
    6
    Views:
    457
    Jim Cheshire [MSFT]
    Jul 29, 2004
Loading...

Share This Page