Difference betwen button and asp:button onclick

后端 未结 5 2118
鱼传尺愫
鱼传尺愫 2020-12-14 08:49

I am new to developing in asp.net for making web sites. So I having some trouble understanding the difference between the following. What is the difference between an asp:Bu

5条回答
  •  有刺的猬
    2020-12-14 09:17

    The first code it is a server side code. When you add a tag asp:button in your webform, the asp.net will render an input type="button" for you and when you click this button, it will submit a post to the same page (this is called postback) and will processing the life cycle and asp.net event associated with this button. The same is valid for every server control such as TextBoxes (render input type='text'), Panels (renders divs), Checkboxes (render input type='checkbox'), Labels (render spans) etc...

    In the second code, you have the code that first one will render (an input type = 'button'), but associated with an event in the client-side javascript.

    You can also associate a client-side event in a tag asp:button, take a look at the OnClientClick property.

提交回复
热议问题