仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 681|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET网页编程之asp.net 2.0里当readonly赶上enablevie...

[复制链接]
海妖 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:34:10 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
在经过全球个人PC市场占有90%的微软对asp.net不断优化与整合后,asp.net与微软自身平台的动用上更加的高效,加上asp.net在应用上非常容易上手,相信asp.net仍会是最多客户选用的脚本语言,并会在未来几年继续领跑。ado|asp.net  偶尔在一个老外的blog里看到有如许的形貌,当textbox控件里被设置为readonly时,并且页面的enableviewsate设置为false时,提交后,textbox的值会丧失,这只产生在asp.net2.0中,在asp.net1.0/1.1中不会呈现如许的情形,代码以下:
<%@PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"EnableViewState="false"Inherits="_Default"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
protectedvoidPage_Load(objectsender,EventArgse)
{
if(!this.IsPostBack)
{
this.Textbox1.Text="readonlytext";
}
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
this.lblMessage.Text=this.Textbox1.Text;
}
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>UntitledPage</title>
</head>
<body>
<formrunat="server"id="Form1">
<asp:textboxID="Textbox1"runat="server"ReadOnly="true"ForeColor="silver"></asp:textbox>
<asp:textboxID="Textbox2"runat="server"ReadOnly="true">SomeText</asp:textbox>
<asp:ButtonID="Button1"runat="server"Text="Button"/><br/>
<asp:LabelID="lblMessage"runat="server"Text="Label"></asp:Label>
</form>
</body>
</html>
  在.net2.0下运转,切实其实会丧失了文本框的值。最初,找到了MSDN的剖析和微软的BUG反应中央,实在这不是BUG,是.net2.0下为了平安的一个小改动,详细摘录以下,人人就分明了:
微软的反应为:
Aftercarefulanalysis,theexplanationfortheobservedbehaviouristhat:
WithadesignchangeinASP.NETbasedonusersecurityconcern,theinputforareadonlytextboxissavedinviewstate,whichdoesnthappenifviewstateisdisabled.Toworkaroundthis,apagedevelopercanaddthereadonlyattributetotheTextBox.Attributescollection,whichcanthenbeusedtoaccessthevalueofthetextbox.
Wehopethisclarifies.Thankyou.
WebServer&Tools
MSDN2005的剖析:
TheTextvalueofaTextBoxcontrolwiththeReadOnlypropertysettotrueissenttotheserverwhenapostbackoccurs,buttheserverdoesnoprocessingforaread-onlytextbox.ThispreventsamalicioususerfromchangingaTextvaluethatisread-only.ThevalueoftheTextpropertyispreservedintheviewstatebetweenpostbacksunlessmodifiedbyserver-sidecode.
一个很大的类库。应用程序之所以难以跨平台,在于直接调用了特定平台的接口,而一个巨大的类库,就能极大地减少应用程序对平台的依赖。
海妖 该用户已被删除
沙发
 楼主| 发表于 2015-3-26 13:33:36 | 显示全部楼层
在调试JSP代码时,如果程序出错,JSP服务器会返回出错信息,并在浏览器中显示。这时,由于JSP是先被转换成Servlet后再运行的,所以,浏览器中所显示的代码出错的行数并不是JSP源代码的行数。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-26 00:55

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表