ͨ¹ýHandlerʵÏÖASP.NET WebForm×Ô¶¨Òå¿Ø¼þ¾Ö²¿Ë¢ÐÂ
¿´µ½ÕâÑùµÄ±êÌ⣬ҲÐíÂíÉÏ»áÓÐÈË˵ֱ½ÓÓÃUpdatePanel²»¾ÍÐÐÁË£¬µÄÈ· Ôڴ󲿷ÖʱºòʹÓÃUpdatePanel¾ÍÄÜʵÏÖÎÒÃÇÐèÒªµÄÒµÎñÐèÇ󣬵«UpdatePanelµÄÁé»îÐÔºÜÓÐÏÞ£¬µ±ÒµÎñÐèÇó±È½Ï¸´ÔÓµÄʱºò£¬¹ý¶àµÄʹÓà UpdatePanel»áµ¼ÖÂÒ³ÃæºÜ¸´ÔÓ£¬Ò²¿ÉÄÜ»áÊÇÒ³ÃæµÄʵÏÖ¿´ÆðÀ´ºÜ±ðŤ£¬ÐÔÄÜÓÐʱºòÒ²²»ÊÇÄÇôÀíÏë¡£
ÄÇôÔÚASP.NET WebFormÀïÃæÄÜ·ñ×Ô¼ºÊµÏÖ¾Ö²¿µÄˢУ¿
Òª×öµ½Ò³ÃæµÄAjax»ñÈ¡·þÎñÆ÷×ÊÔ´²¢²»À§ÄÑ£¬µ«¹Ø¼üÊÇ·þÎñÆ÷ÈçºÎÈ¥×öµ½Ã¿´ÎÖ»ÊÇäÖȾÐèҪˢеIJ¿·Ö£¬¶ø²»ÊÇÕû¸öÒ³Ã棬ÄǽÓÏÂÀ´¾Í½éÉÜÈç¹ûʵÏÖ¾Ö²¿£¨Óû§×Ô¶¨Òå¿Ø¼þ£©µÄäÖȾ¡£
Ê×Ïȶ¨ÒåäÖȾÓû§×Ô¶¨Òå¿Ø¼þµÄ¿ØÖÆÆ÷Àࣺ/// <summary>
/// ÊÓͼÉú³É¿ØÖÆÆ÷
/// </summary>
internal class Controller : Page
{
/// <summary>
/// ¸²¸Ç¿Ø¼þÉú³É
/// </summary>
/// <param name="control"></param>
public override void VerifyRenderingInServerForm(Control control)
{
}
}
½ÓÏÂÀ´¾ÍÊǶ¨ÒåÓû§×Ô¶¨Òå¿Ø¼þµÄÊÇÊÓͼÉú³ÉÒýÇæÀࣺ
/// <summary>
/// ÊÓͼÉú³ÉÒýÇæ
/// </summary>
public class ViewEngine<T> where T : UserControl, IDisposable
{
private Controller _controller;
public ViewEngine()
{
_controller = new Controller();
}
/// <summary>
/// ¼ÓÔؿؼþ
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public T LoadViewControl(string path)
{
_controller.EnableViewState = false;
return (T)_controller.LoadControl(path);
}
/// <summary>
/// Éú³ÉÊÓͼ
/// </summary>
/// <param name="control">¿Ø¼þÀà</param>
/// <returns>·µ»Ø¿Ø¼þHTML</returns>
public string RenderView(T control)
{
try
{
_controller.Controls.Add(control);
StringWriter output = new System.IO.StringWriter();
HttpContext.Current.Server.Execute(_controller, output, false);
_controller.Controls.Clear();
return output.ToString();
}
catch { return string.Empty; }
}
/// <summary>
/// Ê©·Å×ÊÔ´
/// </summary>
public void Dispose()
{
_controller.Dispose();
}
}
ÏÖÔÚ¼òµ¥µÄÊÓͼÒýÇæ»ù±¾¾ÍÒѾÍê³É£¬È»ºó¾ÍÊÇÈçºÎʹÓøÃÊÓͼÒýÇæäÖȾÓû§×Ô¶¨Òå¿Ø¼þ£¬È»ºó·µ»ØÓû§Ò³Ãæ¡£
¼ÙÉèÏÖÔÚÐèÒªÒì²½³ÊÏÖÓû§×Ô¶¨Òå¿Ø¼þUserGet.aspx,ÄÇô¶¨ÒåÒ»¸öÓû§×Ô¶¨ÒåHandlerÓÃÀ´½ÓÊÕÒ³ÃæµÄAjaxÇëÇó£º
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
int id = int.Parse(context.Request.Form["id"]);
var user = Data.Users.FirstOrDefault(u=>u.ID == id);
var engine = new ViewEngine<UserGet>();
UserGet view = engine.LoadViewControl("/Controls/UserGet.ascx");
view.DataBind(user);
context.Response.Write(engine.RenderView(view));
engine.Dispose();
context.Response.Flush();
}
¸ù¾ÝÓû§PostµÄÐÅÏ¢»ñÈ¡Óû§·´À¡ÐÅÏ¢£¬È»ºóͨ¹ýÇ°Ã涨ÒåµÄÊÓͼÒýÇæ¼ÓÔØÓû§×Ô¶¨Òå¿Ø¼þ²¢»ñÈ¡Óû§×Ô¶¨Òå¿Ø¼þ¶ÔÏó£¬È»ºó½«Êý¾Ý°ó¶¨µ½Óû§×Ô¶¨Òå¿Ø¼þ¶ÔÏó£¬×îºó½«äÖȾ½á¹ûдÈëResponse·µ»ØÓû§¡£
ÔÚÒ³ÃæAjaxÇëÇó¶¨ÒåµÄHandler£¬È»ºó¸ù¾Ý·µ»Ø½á¹ûÌæ»»Ò³ÃæÔªËØ£º
<script type="text/javascript">
function getUserDetail(id) {
$.post("/Controls/UserGetHandler.ashx", { id: id }, function (result) {
$("#divUserDitail").html(result);
});
}
</script>
ÕâÑù»ù±¾¾ÍʵÏÖÒ³ÃæµÄ¾Ö²¿Ë¢Ð£¬µ«ÕâÑùµÄ¾Ö²¿Ë¢ÐÂËäÈ»»á±È½ÏÁé»î£¬µ«Ò²Ôö¼ÓÁË¿ª·¢µÄ¹¤×÷Á¿¡£
×¢Ò⣺ͨ¹ý¸Ã·½Ê½¾Ö²¿Ë¢ÐµÄÓû§×Ô¶¨Òå¿Ø¼þÊÇÎÞ״̬µÄ¡£
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- Asp.net MVCÔ´Âë·ÖÎö--Model Validation(Se....
- .Net À¬»ø»ØÊÕ»úÖÆÔÀíºÍËã·¨£¨Ò»£©
- .netʵÌåнâ
- ·ÖÎöASP.NET¶ÁÈ¡XMLÎļþ4ÖÖ·½·¨
- »ñÈ¡ÍøÕ¾ËõÂÔͼ´úÂë
- Asp.net ¸ù¾ÝIPµØÖ·»ñÈ¡¿çÍø¶ÎmacµØÖ·º¯Êý¡¾ËѲء¿
- ¹ýÂËÃô¸Ð¹Ø¼ü×Ö¡£
- Éú³ÉÖ¸¶¨Î»ÊýµÄËæ»ú×Ö·û´®
- ¿Í»§¶Ë»ñÈ¡MACµØÖ·£¬µ½·þÎñÆ÷ÑéÖ¤
- ²½²½ÎªÓª .NETÈý²ã¼Ü¹¹½âÎö ¶þ¡¢Êý¾Ý¿âÉè¼Æ
ÆÀÂÛ