ASP.NetÖпؼþµÄEnableViewStateÊôÐÔ ¡¾×ªÔØ¡¿
ÔÚASP.NetÖжԸ÷¸öWebForm¿Ø¼þÒýÈëÒÔǰûÓеÄEnableViewStateÊôÐÔ¡£Õâ¸öÊôÐÔ¾¿¾¹ÓÐʲôÓá£ÎÒÃÇÖªµÀ¶ÔÓÚWebForm¶øÑÔ£¬Æä´úÂëÊÇÔÚ·þÎñÆ÷¶ËµÄ£¬ÒÔ´¦Àí¿Í»§¶ËµÄÇëÇó¡£µ±Óû§Í¨¹ýä¯ÀÀÆ÷ä¯ÀÀÍøÒ³µÄʱºò£¬»á¶ÔÍøÒ³½øÐÐijЩ²Ù×÷£¬±ÈÈç´ò¿ªÐÂÁ´½Ó£¬»òµ¥»÷ij¸ö°´Å¥¡£ÔÚASPÖУ¬ÕâЩÊÇͨ¹ý½Å±¾ÓïÑÔ¶ÔÆä½øÐд¦Àí£¬Ö®ºóÔÙ´«µÝ¸ø·þÎñÆ÷¶Ë¡£µ«ÊÇÔÚASP.NETÏ£¬ÓÉÓÚ²ÉÓÃÁËcode behind¼¼Êõ£¬ÔÚcodingµÄʱºò£¬Í¨³£Êǽ«ÒÔÇ°¿Í»§¶ËÍê³ÉµÄ¹¤×÷·Åµ½ÁË·þÎñÆ÷¶Ë¡£
ÄÇô£¬·þÎñÆ÷ÊÇÔõô֪µÀ¿Í»§µÄ²Ù×÷µÄÄØ£¿±ÈÈçÎÒÔÚÎı¾¿òÊäÈëµÄÄÚÈÝ£¬»òÕßµ¥»÷Á˵Ǽ°´Å¥£¬·þÎñÆ÷¶ËÊÇÔõÑùµÃµ½ÕâЩÐÅÏ¢µÄÄØ£¿ÒòΪûÓÐÕâЩÐÅÏ¢£¬·þÎñÆ÷¶Ë¾ÍÎÞ·¨ÏìÓ¦¿Í»§µÄÇëÇó¡£ÔÀí¾ÍÊÇASP.NETÒýÓÃÁËviewstateµÄ»úÖÆ¡£ÔÚ·þÎñÆ÷¶Ë±£´æÁËÍøÒ³¸÷¸ö¿Ø¼þ¼°Ò³ÃæµÄ״̬£¬ÕâÆäÖаüÀ¨¸÷¸ö¿Ø¼þÔÚÒ³ÃæÉϵIJ¼¾Ö£¬ºÍËûÃǸ÷×ÔµÄÊôÐÔ¡£ÕâЩֵ¾Í±£´æÔÚViewStateÏ¡£ÎÒÃÇ¿ÉÒÔ¹Û²ìAspxÒ³ÃæµÄhtmlÔ´´úÂ룬¼ÙÉèÕâ¸öÒ³ÃæÉÏÓÐÒ»¸öbutton°´Å¥£¬ºÍÒ»¸ölistBox¿Ø¼þ£¬htmlÎļþÈçÏ£º
<input type="hidden" name="__VIEWSTATE" value="dDwzODYzNDM5NTU7Oz7FvviJbq45bDa7QJaumIiOhZ8mOQ==" />
<input type="submit" name="Button1" value="Button" id="Button1" style="height:40px;width:96px;Z-INDEX: 101; LEFT: 200px; POSITION: absolute; TOP: 240px" />
<select name="ListBox1" size="4" id="ListBox1" style="width:152px;Z-INDEX: 102; LEFT: 176px; POSITION: absolute; TOP: 120px"></select>
ÎÒÃÇËüµÄ²»Í¬Ö®´¦£¬Ò»ÊÇÉÙÁËÒÔÇ°Ëù±ØÐëÏìÓ¦¿Í»§¶ËʼþµÄ½Å±¾ÓïÑÔ£¬Ò»ÊǶàÁËÒ»¸öÃûΪ”_VIEWSTATE”µÄÊôÐÔ¡£ÆäÖµÊÇÒ»³¤´®×Ö·û¡£ÀàÐÍΪ“hidden”¡£Õâ¸öÖµ¼Ç¼µÄ¾ÍÊǸ÷¸ö¿Ø¼þºÍÒ³ÃæµÄ״̬ÐÅÏ¢¡£µ±Óû§¶ÔÒ³Ãæ½øÐÐÏà¹Ø²Ù×÷µÄʱºò£¬×´Ì¬Öµ·¢Éú¸Ä±ä£¬²¢½«¸Ä±äµÄÖµ´«µÝ¸ø·þÎñÆ÷¶Ë¡£·þÎñÆ÷¶ËÔڱȽϸıäºóµÄ״ֵ̬ºÍ³õʼֵ֮¼äµÄÇø±ð£¬ÒÔÏìÓ¦¾ßÌåµÄÇëÇó¡£
Ò»µ©Ò³ÃæµÄ¿Ø¼þºÜ¶à£¬ÕâÖÖƵ·±µÄ´«µÝ¿Ø¼þ״ֵ̬¶ÔÍøÂçµÄÏûºÄÊǺܴóµÄ£¬Òò´Ë£¬ASP.NetÌṩÁËEnableViewStateÊôÐÔ£¬ÏµÍ³Ä¬ÈϵÄֵΪtrue¡£µ±ÉèÖÃΪtrueʱ£¬ÔÚ´«µÝ״ֵ̬ʱ¾Í°üÀ¨¸Ã¿Ø¼þ£»Èç¹ûÉèÖÃΪfalse£¬Ôò´«µÝ״ֵ̬ʱÔò²»°üÀ¨Ëü¡£¼ÈȻ״ֵ̬²»°üÀ¨¸Ã¿Ø¼þ£¬Ôò¿Í»§¶Ë¶ÔËü½øÐеIJÙ×÷£¬·þÎñÆ÷¶ËÊDz»ÏìÓ¦µÄ¡£
ÎÒÃÇ¿ÉÒÔ×ö¸öʵÑ飬ÔÚButton1_ClickʼþÖУ¬±àд´úÂ룺
ListBox.Items.Add(”¿Í»§¶Ëµã»÷°´Å¥Ò»´Î£¡”);
´ËÊ
Ïà¹ØÎĵµ£º
ASP.NET ÌṩÈýÖÖÓÃÓÚÔÚ³öÏÖ´íÎóʱ²¶»ñºÍÏìÓ¦´íÎóµÄÖ÷Òª·½·¨£ºPage_Error ʼþ¡¢Application_Error ʼþÒÔ¼°Ó¦ÓóÌÐòÅäÖÃÎļþ (Web.config)¡£
Èç¹ûÄú²»µ÷Óà Server.ClearError »òÕß²¶»ñ Page_Error »ò Application_Error ʼþÖеĴíÎó£¬Ôò½«¸ù¾Ý Web.config ÎļþµÄ <customErrors> ²¿·ÖÖеÄÉèÖô¦Àí´íÎó¡£ÔÚ <cus ......
±¾ÌùÀ´×ÔZDNetChinaÖÐÎÄÉçÇø http://bbs.zdnet.com.cn/
±¾ÌùµØÖ·£ºhttp://bbs.zdnet.com.cn/viewthread.php?tid=108315
Èç¹ûÄãÒѾÓн϶àµÄÃæÏò¶ÔÏ󿪷¢¾Ñ飬Ìø¹ýÒÔÏÂÕâÁ½²½£º
¡¡¡¡µÚÒ»²½¡¡ÕÆÎÕÒ»ÃÅ.NETÃæÏò¶ÔÏóÓïÑÔ£¬C#»òVB.NET ÎÒÇ¿ÁÒ·´¶ÔÔÚûϵͳѧ¹ýÒ»ÃÅÃæÏò¶ÔÏó(OO)ÓïÑÔµÄÇ°ÌáÏÂȥѧASP.NET¡£ ASP.NETÊÇ ......
ÔÚasp.netÀïÃ棬ºÜ¶àʱºòʹÓÃsessionÀ´±£´æһЩ¶ÔÏ󣬱ÈÈç˵¹ºÎï³µµÈµÈ£¬Óкܶàʱºò£¬¾ÍËãÄãÉèÖÃÁËsession³¬Ê±µÄʱ¼ä£¬session»¹ÊÇ»áÎÞÔµÎ޹ʵĶªÊ§£¬ÕâÀïÓÐÒ»ÖֱȽϼòµ¥µÄ·½·¨¿ÉÒÔÉèÖÃsession¶ªÊ§µÄʱ¼ä¡£
ÔÚweb.configÀïÃæÈçÏÂÅäÖÃ
<sessionState
& ......
PRB£ºÔÚʹÓà Response.End¡¢Response.Redirect »ò Server.Transfer ʱ³öÏÖ ThreadAbortException
Ö¢×´
Èç¹ûʹÓà Response.End¡¢Response.Redirect »ò Server.Transfer ·½·¨£¬½«³öÏÖ ThreadAbortException Òì³£¡£Äú¿ÉÒÔʹÓà try-catch Óï¾ä²¶»ñ´ËÒì³£¡£
ÔÒò
Response.End ·½·¨ÖÕÖ¹Ò³µÄÖ´ÐУ¬²¢½«´ËÖ´ÐÐÇл»µ½Ó¦ÓóÌÐò ......
ûÓÐ×ÐϸÑо¿¹ýViewState£¬×î½ü³öÏÖµÄÎÊÌâÈÃÈËÍ·Í´²»ÒÑ¡£
ViewState»áÔÚijЩÌض¨Çé¿öÏÂÏûʧ£¬ÇÒºÜÄѲ¶×½µ½¡£²éÁËһЩ¼¼ÊõÎÄÕ£¬¶¼ÊÇ˵ViewStateµÄ»úÖÆÊǽ«ÐÅÏ¢´æÔÚÒ³ÃæµÄhidden inputÀïÃ棬Ëƺõ²»¿ÉÄÜ´æÔÚÕâЩÎÊÌ⣬¸ø³öµÄÀíÓÉÎÞ·ÇÊÇÔÚij¸öµØ·½±»Ä³¸ö²»Ð¡ÐĵijÌÐòÔ±¸ø½ûµô»òÇå³ýµôÁ ......