input type=button与asp:button的区别,以及runat=server的作用
<input type="button">與<asp:button>的區(qū)別,以及runat="server"的作用
在<input type="button">中只能編寫點(diǎn)擊事件onclick,并且只能在js中實(shí)現(xiàn),那么如何讓<input type="button">像<asp:button>一樣可以在后臺(tái)實(shí)現(xiàn)呢
為<input type="button" >添加runat="server" 并且添加onserverclick="Unnamed_ServerClick"點(diǎn)擊事件,并在后臺(tái)編寫它的點(diǎn)擊效果,這樣就會(huì)跟<asp:button>效果一樣。
<input type="button">前臺(tái)代碼:
? ? ?<input type="button" name="name" value="確定" runat="server"(服務(wù)器控件的意思是在里頁面上建立了普通HTML標(biāo)簽或ASP.NET服務(wù)器控件,他們需要在控件加上runat="server"來標(biāo)記為服務(wù)器控件,ASP.NET就會(huì)解析進(jìn)行一系列的處理,在后臺(tái)都可以調(diào)用通過標(biāo)記的控件,獲取你需要對控件的一系列取值要求) onserverclick="Unnamed_ServerClick" />
? ? ?后臺(tái)代碼:
? ? ? protected void Unnamed_ServerClick(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? Response.Write("<script>alert('點(diǎn)擊有效果了!');</script>");
? ? ? ? }
<asp:button>前臺(tái)代碼:
? ? ?<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
? ? ? 后臺(tái)代碼:
? ? ??protected void Button1_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ?Response.Write("<script>alert('你好!');</script>");
? ? ? ? }
總結(jié)
以上是生活随笔為你收集整理的input type=button与asp:button的区别,以及runat=server的作用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 得到app文稿导出_逻辑思维,阅读付费平
- 下一篇: 牛客在线编程101-93 盛水最多的容器