Difference betwen button and asp:button onclick

非 Y 不嫁゛ 提交于 2019-11-28 20:30:36

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.

The first is a server side control and the event handler is executed on the server in C#. Clicking the button will cause a postback and all information in the form will be posted to the server for processing, including a call to the click event handler.

The second is fully client side and the event handler is executed in the browser in JavaScript.

asp:Button is an asp.net server control which fire an event on the server side.

<input id="Submit1" type="submit"

is a client side button of type submit, but it can act as a server side button as well by adding

runat="server" and onserverclick="eventname"

to my understanding you have to keep in mind that there is a cliend side code that will execute, for example javascript in your browser, and asp/c# code that will execute on the server.

So having this control:

 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 

Button1_Click will execute on the server, in microsoft world it is IIS, on the other hand you have just a pure html control, where you hook up a javascript function for the click event

 <input id="Submit1" type="submit" value="submit" onclick="return Submit1_onclick()" /> 

So the server side has nothing to do with this part, this code will execute on your machine, in your browser.

A mí me funcionó así:

1.- En el botón:

 <input type="submit" id="btnAccept" value="Log In" runat="server" onserverclick="btnAccept_Click">

2.- En el codebehind:

Protected Sub btnAccept_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!