How postback works in ASP.NET
Introduction
In this article, we will take a closer look at how ASP.NET pages post back to themselves, and how to customize this feature in our web applications.
function __doPostBack(eventTarget, eventArgument)
One of the most important features of the ASP.NET environment is the ability to declare controls that run on the server, and post back to the same page. Remember the days of classic ASP? We would create a form which would accept the user's input, and then we would most probably have to create another page that would accept all those inputs, either through HTTP GET or POST, and perform some kind of validation, display and action. Sometimes, even a third page was necessary to perform our actions. This wasted a lot of time and complicated things when you had to make a change. But of course, this is not necessary any more with ASP.NET. There is no need to create second pages that accept the inputs of the first, process them and so on. Form fields and other controls can be declared to run on the server, and the server simply posts the page back to itself and performs all the validation, display and actions. Our life as web developers has become a million times better. But how exactly is this done?
When a control is declared to run on the server, a VIEWSTATE is created which remembers the ID of that control, and the method to call when an action is performed. For example, let's say we input this HTML on a page:
1
<script language="VB" runat="server">
2
Sub Test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
3
'enter your code to perform
4
End Sub
5
</script>
6
<html>
7
<body>
8
<form runat="server" id="myForm">
9
<asp:linkbutton id="Test" runat="server" text="Create Text file" onclick="Test_Click" />
10
</form>
11
</body>
12
</html>
&n
Ïà¹ØÎĵµ£º
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient;//ÒýÈëÃüÃû¿Õ¼ä ......
Ò³ÃæµØÖ·ÊÇ:http://www.mldn.cn/articleview/2007-2-6/article_view_1400.htm
Web·þÎñµÄinetinfo.exeÓëOracleµÄApache.exe½ø³ÌËùÕ¼ÓõĶ˿ڶ¼°üÀ¨80¶Ë¿Ú¡£
Èç¹ûÓû§ÊÇÔÚ°²×°ÁËOracleÖ®ºó£¬ÔÙʹÓÃ.NET´´½¨ASP.NETÓ¦ÓóÌÐò³öÏÖÏÂÃæÇé¿öµÄ´íÎó£º
VS.NET¼ì²âµ½web·þÎñÆ÷ÔËÐеÄÊÇASP.NET 1.0°æ£¬Òª´´½¨»ò´ò¿ªµÄÓ¦ÓóÌÐò¿ÉÒ ......
ÉúÃüÖÜÆÚ²½Öè¸ÅÀÀ
µ±ÎÒÃǶÔASP.NET MVCÍøÕ¾·¢³öÒ»¸öÇëÇóµÄʱºò£¬»á·¢Éú5¸öÖ÷Òª²½Ö裺
²½Öè1£º´´½¨RouteTable
µ±ASP.NETÓ¦ÓóÌÐòµÚÒ»´ÎÆô¶¯µÄʱºò²Å»á·¢ÉúµÚÒ»²½¡£RouteTable°ÑURLÓ³Éäµ½Handler¡£
²½Öè2£ºUrlRoutingModuleÀ¹½ØÇëÇó
µÚ¶þ²½ÔÚÎÒÃÇ·¢ÆðÇëÇóµÄʱºò·¢Éú¡£UrlRoutingModuleÀ¹½ØÁËÿһ¸öÇëÇó²¢ÇÒ´´½¨ºÍÖ´ÐкÏÊ ......
µÚÒ»ÖÖ·½·¨£º
ͨ¹ýURLÁ´½ÓµØÖ·´«µÝ
send.aspx:
protected void Button1_Click(object sender, EventArgs e)
{
Request.Redirect("Default2.aspx?username=honge");
}
receive.aspx:
string user ......
ʹÓÃGridview°ó¶¨Êý¾Ý¿âÖеÄͼƬ(תÔØ)
×¢£º´ËϵÁмǼÔÚÎÒʵ¼Ê¿ª·¢ÖÐÓöµ½µÄÎÊÌâºÍÊÕ²ØһЩ¼¼ÇÉÎÄÕ¡£
ÎÒÃǶ¼ÖªµÀ£¬ÔÚGridviewÖв»ÄÜÖ±½ÓÈ¥°ó¶¨Êý¾Ý¿âÖеÄͼƬ£¬ÎÒÃÇ¿ÉÒÔÀûÓÃHttpHandlerºÜÈÝÒ×µÄÍê³ÉÕâ¸öÈÎÎñ£¬ÔÚÕâÀïÎҼǼһÏÂÕâ¸ö¹ý³Ì¡£
1.ÉÏ´«Í¼Æ¬´æ´¢µ½Êý¾Ý¿âÖÐ
ÔÚÊý¾Ý¿âÖд´½¨Ò»¸ö±í£¬Ìí¼ÓÒ»ÏÂ3¸ö×ֶΣº
²½ÖèÒ»£ ......