按钮和asp之间的区别:按钮onclick [英] Difference between button and asp:button onclick
问题描述
我不擅长在asp.net中开发网站.
I am new to developing in asp.net for making web sites.
asp:Button
和输入按钮之间有什么区别?
What is the difference between an asp:Button
and an input button?
代码1
aspx代码
Code 1
aspx code
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
隐藏代码
protected void Button1_Click(object sender, EventArgs e)
{
//Do somthing
}
代码2
aspx代码
Code 2
aspx code
<input id="Submit1" type="submit" value="submit" onclick="return Submit1_onclick()" />
<script language="javascript" type="text/javascript">
// <![CDATA[
function Submit1_onclick() {
//Do somthing
}
// ]]>
</script>
推荐答案
第一个代码是服务器端代码.当您在网络表单中添加标签 asp:button
时,asp.net将为您呈现一个 input type ="button"
,并且当您单击此按钮时,它将将帖子提交到同一页面(称为 postback
),并将处理与该按钮关联的生命周期和asp.net事件.对于每个服务器控件(例如 TextBoxes
(呈现 input type ='text'
), Panels
(渲染divs),复选框
(呈现 input type ='checkbox'
),标签
(呈现 spans
)等...
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...
在第二个代码中,您具有第一个将呈现的代码( input type ='button'
),但是与客户端javascript中的事件相关联.
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.
您还可以在标签 asp:button
中关联客户端事件,看看 OnClientClick
属性.
You can also associate a client-side event in a tag asp:button
, take a look at the OnClientClick
property.
这篇关于按钮和asp之间的区别:按钮onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!