asp.net(c#) static¹Ø¼ü×ÖÓ÷¨Ð¡½á[zz]
http://ayic1.blog.163.com/blog/static/27343030200965103528805/
¾²Ì¬±äÁ¿
µ±ÎÒÃDZàдһ¸öÀàʱ£¬Æäʵ¾ÍÊÇÔÚÃèÊöÆä¶ÔÏóµÄÊôÐÔºÍÐÐΪ£¬¶ø²¢Ã»ÓвúÉúʵÖÊÉϵĶÔÏó£¬Ö»ÓÐͨ¹ýnew¹Ø¼ü×ֲŻá²úÉú³ö¶ÔÏó£¬Õâʱϵͳ²Å»á·ÖÅäÄÚ´æ¿Õ¼ä¸ø¶ÔÏó£¬Æä·½·¨²Å¿ÉÒÔ¹©Íⲿµ÷Óá£
ÓÐʱºò£¬ÎÒÃÇÏ£ÍûÎÞÂÛÊÇ·ñ²úÉúÁ˶ÔÏó»òÎÞÂÛ²úÉúÁ˶àÉÙ¶ÔÏóµÄÇé¿öÏ£¬Ä³Ð©Ìض¨µÄÊý¾ÝÔÚÄÚ´æ¿Õ¼äÀïÖ»ÓÐÒ»·Ý£¬ÀýÈçËùÓеÄÖйúÈ˶¼Óйú¼ÒÃû³Æ£¬Ã¿Ò»¸öÖйúÈ˶¼¹²ÏíÕâ¸ö¹ú¼ÒÃû³Æ£¬²»±ØÔÚÿһ¸öÖйúÈ˵ÄʵÀý¶ÔÏóÖж¼µ¥¶À·ÖÅäÒ»¸öÓÃÓÚ´úÂë¹ú¼ÒÃû³ÆµÄ±äÁ¿¡£Àý×Ó£º
protected void Page_Load(object sender, EventArgs e)
{
//Ö±½ÓʹÓÓÀàÃû.³ÉÔ±”µÄ¸ñʽ£¬²»ÄÜʹÓÓ¶ÔÏóÃû.³ÉÔ±”µÄ¸ñʽ£¬ÕâµãÓëJAVA²»Ò»Ñù£¬JAVAÁ½ÖÖ¶¼¿ÉÒÔʹÓÃ
Response.Write(Chinese.Country);
}
class Chinese
{
public static string Country = "Öйú";
public void getCountry()
{
//ÀàÖеijÉÔ±·½·¨Ò²¿ÉÒÔÖ±½Ó·ÃÎʾ²Ì¬³ÉÔ±±äÁ¿
HttpContext.Current.Response.Write("ÄãºÃ£¡" + Country);
}
}
ÐèҪעÒâµÄÊÇ£º²»ÄÜ°ÑÈκη½·¨ÌåÄڵıäÁ¿ÉùÃ÷Ϊ¾²Ì¬£¬ÈçÏÂÃæÕâÑùÊDz»Ðеģº
public void getCountry()
{
//ÀàÖеijÉÔ±·½·¨Ò²¿ÉÒÔÖ±½Ó·ÃÎʾ²Ì¬³ÉÔ±±äÁ¿
HttpContext.Current.Response.Write("ÄãºÃ£¡" + Country);
static int i = 1;
}
¾²Ì¬·½·¨
ÎÒÃÇÓÐʱҲϣÍû²»±Ø´´½¨¶ÔÏó¾Í¿ÉÒÔµ÷ÓÃij¸ö·½·¨£¬»»¾ä»°ËµÒ²¾ÍÊÇʹ¸Ã·½·¨²»±ØºÍ¶ÔÏó°ó¶¨ÔÚÒ»Æð¡£ÒªÊµÏÖÕâÑùµÄЧ¹û£¬Ö»ÐèÒªÔÚÀàÖж¨ÒåµÄ·½·¨Ç°¼ÓÉÏstatic¹Ø¼ü×־ͿÉÒÔÁË£¬ÎÒÃdzÆÕâÖÖ·½·¨Îª¾²Ì¬³ÉÔ±·½·¨£¬»¹¿ÉÒÔÔÚÀàµÄ·Ç¾²Ì¬³ÉÔ±·½·¨ÖÐÏó·ÃÎÊÆäËû¾²Ì¬·½·¨Ò»ÑùÈ¥·ÃÎÊÕâ¸ö¾²Ì¬·½·¨£¬Àý×Ó£º
prot
Ïà¹ØÎĵµ£º
1. Êý¾Ý¿â·ÃÎÊÐÔÄÜÓÅ»¯¡¡
¡¡
Êý¾Ý¿âµÄÁ¬½ÓºÍ¹Ø±Õ
·ÃÎÊÊý¾Ý¿â×ÊÔ´ÐèÒª´´½¨Á¬½Ó¡¢´ò¿ªÁ¬½ÓºÍ¹Ø±ÕÁ¬½Ó¼¸¸ö²Ù×÷¡£ÕâЩ¹ý³ÌÐèÒª¶à´ÎÓëÊý¾Ý¿â½»»»ÐÅÏ¢ÒÔͨ¹ýÉí·ÝÑéÖ¤£¬±È½ÏºÄ·Ñ·þÎñÆ÷×ÊÔ´¡£ASP.NETÖÐÌṩÁËÁ¬½Ó³Ø(Connection Pool)¸ÄÉÆ´ò¿ªºÍ¹Ø±ÕÊý¾Ý¿â¶ÔÐÔÄܵÄÓ°Ï졣ϵͳ½«Óû§µÄÊý¾Ý¿âÁ¬½Ó·ÅÔÚÁ¬½Ó³ØÖУ¬ÐèҪʱȡ³ö£¬¹Ø±ÕÊ±Ê ......
1. Êý¾Ý¿â·ÃÎÊÐÔÄÜÓÅ»¯¡¡
¡¡
Êý¾Ý¿âµÄÁ¬½ÓºÍ¹Ø±Õ
·ÃÎÊÊý¾Ý¿â×ÊÔ´ÐèÒª´´½¨Á¬½Ó¡¢´ò¿ªÁ¬½ÓºÍ¹Ø±ÕÁ¬½Ó¼¸¸ö²Ù×÷¡£ÕâЩ¹ý³ÌÐèÒª¶à´ÎÓëÊý¾Ý¿â½»»»ÐÅÏ¢ÒÔͨ¹ýÉí·ÝÑéÖ¤£¬±È½ÏºÄ·Ñ·þÎñÆ÷×ÊÔ´¡£ASP.NETÖÐÌṩÁËÁ¬½Ó³Ø(Connection Pool)¸ÄÉÆ´ò¿ªºÍ¹Ø±ÕÊý¾Ý¿â¶ÔÐÔÄܵÄÓ°Ï졣ϵͳ½«Óû§µÄÊý¾Ý¿âÁ¬½Ó·ÅÔÚÁ¬½Ó³ØÖУ¬ÐèҪʱȡ³ö£¬¹Ø±ÕÊ ......
ASP.NET MVCºÍWebForm¸÷Óи÷µÄÓŵ㣬ÎÒÃÇ¿ÉÄÜÐèҪͬʱʹÓÃASP.NET MVCºÍWebForm¡£±¾ÎĽéÉÜÁËÈçºÎÔÚASP.NET MVCÏîÄ¿ÖÐʹÓÃWebForm¡£
Ê×ÏÈн¨Ò»¸öÃûΪWebFormsµÄÎļþ¼ÐÓÃÓÚ´æ·ÅWebForm£¬²¢Ìí¼ÓÒ»¸öWeb´°ÌåÎļþDemo.aspx×÷ΪÑÝʾ¡£
Demo.aspx¾Í¼òµ¥µÄÊä³öÒ»¾ä»°“It’s a WebForm.”
¹Ø¼ü²½ÖèÔÚÓÚ·ÓÉÉèÖá ......
·½·¨Ò»:
public void page_load(Object obj,EventArgs e)
{
//´´½¨·þÎñÆ÷¶Ë¿Ø¼þ.
//Ö¸¶¨µÄ±ê¼Ç"LINK"³õʼ»¯´ËÀàµÄÐÂʵÀý.
HtmlGenericControl objLink=new HtmlGenericControl("LINK");
objLink.ID=ID;
objLink.Attributes["rel"]="stylesheet ......
ÔÚÓÃGridView¿Ø¼þʱ£¬ÎÒÃǾ³£»áÅöµ½»ñÈ¡µ±Ç°ÐеÄË÷Òý£¬Í¨¹ýË÷Òý½øÐÐÐí¶à²Ù×÷¡£ÀýÈ磬¿ÉÒÔ»ñµÃµ±Ç°ÐÐijһ¸ö¿Ø¼þÔªËØ£»ÉèÖÃijһԪËصÄÖµµÈµÈ¡£
ÏÂÃæ½áºÏʵÀý½éÉܼ¸ÖÖ»ñµÃGridViewµ±Ç°ÐÐË÷ÒýÖµµÄ·½·¨¡£
ʵÀý£º
¢Ù Ä¿µÄ£º»ñÈ¡GridViewÖÐRowCommandµÄµ±Ç°Ë÷ÒýÐС£
¢Ú ǰ̨ҳÃ棺ÔÚGridViewÖÐÌí¼Óһģ°æÁУ¬ÀïÃæÌí¼ÓÒ»¸öLink ......