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