OnClick vs OnClientClick for an asp:CheckBox?

后端 未结 8 1374
我在风中等你
我在风中等你 2020-12-07 16:33

Does anyone know why a client-side javascript handler for asp:CheckBox needs to be an OnClick=\"\" attribute rather than an OnClientClick=\"\" attribute, as for asp:Button?<

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 16:53

    Because they are two different kinds of controls...

    You see, your web browser doesn't know about server side programming. it only knows about it's own DOM and the event models that it uses... And for click events of objects rendered to it. You should examine the final markup that is actually sent to the browser from ASP.Net to see the differences your self.

    
    

    renders to

    
    

    and

    
    

    renders to

    
    

    Now, as near as i can recall, there are no browsers anywhere that support the "OnClientClick" event in their DOM...

    When in doubt, always view the source of the output as it is sent to the browser... there's a whole world of debug information that you can see.

提交回复
热议问题