ASP.NET狀態視圖小測試-1

來源:互聯網
上載者:User

  對於asp.net提交後究竟有哪些東西,它是依舊在維護的,我一直很模糊,自己做了一個測試,發現用戶端指令碼改掉的東西,它都是不維護的,看來,除非是伺服器控制項,而且是在伺服器端變更的東西,它是儲存到檢視狀態進行維護的,其他的,它不管,你一重新整理或者一提交,它統統回原樣了!

上代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function outbtn_click()
{
document.getElementById("outDiv").innerHTML = "我改掉你了!!";
document.getElementById("inDiv").innerHTML = "我改掉你了!!";
document.getElementById("Label1").innerHTML = "我改掉你了!!";
}
</script>
</head>
<body>
<div id="outDiv">我在外面</div>
<input type="button" value="outbn" onclick="outbtn_click()" />
<form id="form1" runat="server">
<div id="inDiv">
haha,我這個div在form裡面,測試一下看asp會自動給我維護狀態的
</div>

<asp:Label ID="Label1" runat="server" Text="我是伺服器端控制項,來吧,我不怕!"></asp:Label>
<br />
<asp:Button Text="button" runat="server"/>
</form>
</body>
</html>

按outbn按鈕後,通過用戶端js,修改需測試的控制項內容,如下:

按button按鈕,內容全部變回來了,不管是form外也好,form內也好,甚至是伺服器控制項,由於是用戶端改變的內容,沒有進入狀態視圖內,因此提交後無法儲存。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.