差异悫按钮和ASP:按钮的onclick [英] Difference betwen button and asp:button onclick
问题描述
我是新来的asp.net制作网站的发展。所以,我有一些麻烦理解以下的区别。什么是一个asp的区别:按钮和输入按钮?
code 1 结果
ASPX code
< ASP:按钮的ID =Button1的=服务器的onclick =的button1_Click文本=按钮/>
codebehind
保护无效的button1_Click(对象发件人,EventArgs的发送)
{
//财产以后做
}
code 2 结果
ASPX code
<输入ID =Submit1类型=提交值=提交的onclick =返回Submit1_onclick()/>
< SCRIPT LANGUAGE =JavaScript的类型=文/ JavaScript的>
//<![CDATA [功能Submit1_onclick(){
//财产以后做
}//]]>
< / SCRIPT>
第一个code这是一个服务器端code。当您添加标签 ASP:在你的网页表单按钮
时,asp.net将呈现一个输入类型=按钮
你,当你点击这个按钮,它会提交一篇文章到同一个页面(这被称为回发
),并处理相关的生命周期和asp.net事件使用此按钮。这同样适用于每一个服务器控件,如文本框
(渲染输入类型=文本
),面板
(呈现的div),复选框
(渲染输入类型=复选框
),标签
(渲染跨度
)等等...
在第二code,你有code,它第一个将使(输入类型=按钮
),但与关联事件在客户端JavaScript。
您也可以一个客户端事件的标记 ASP关联:按钮
,看看在的OnClientClick
属性。
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:Button and an input button?
Code 1
aspx code
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
Codebehind
protected void Button1_Click(object sender, EventArgs e)
{
//Do somthing
}
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>
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.
这篇关于差异悫按钮和ASP:按钮的onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!