מה ההבדל בין WebControls ל HtmlCont

Afik17

New member
מה ההבדל בין WebControls ל HtmlCont

HtmlControls ? קראתי עמוד ב MSDN המסכם את ההבדלים בינהם, הנתי ש Html ם יותר פרימיטיבים, פחות פונקציונאלים, אך יותר מהירים. 1. איזו פונקציונליות יש ב HtmlControls שאין ב WebControls לדוגמא ? 2. האם יש הבדל ברינדור שלהם ? למשל, אם אני מגדיר WebControl, אז הוא נוצר בצד השרת. אם אני מגדיר HtmlControl, הוא מרונדר על המסך כמו כל אובייקט HTML רגיל, ופשוט ניתן לפנות אליו מצד שרת - האם יש הבדל ?
 

nattygur

New member
הבדלים בין HTMLControls ל WebContro

ההבדל העקרוני ביותר ש WebControls תומכים באירועים בצד שרת וב Attribute שמיצר הפקדים כתב לעומת HTMLControls אשר אינו תומך באירועים או ב Attributes שונים. בכדי להשתמש ב HTMLControls מצד שרת ניתן להוסיף להם את המאפין RUNAT=server ואז ניתן להשתמש ברכיב בצד שרת (הוא למעשה WEBControl וניתן להשתמש רק בפונקציונאליות ש WebControl חושף, ללא אירועים). לגבי Render ה WebControls הם רכיבים אשר מיוצרים בזמן ריצה ובאחריותם לרנדר את ה HTML שלהם :
private System.Web.UI.Control __BuildControlTextBox1() { System.Web.UI.WebControls.TextBox __ctrl; #line 14 "http://localhost/WebApplication22/WebForm16.aspx" __ctrl = new System.Web.UI.WebControls.TextBox(); #line default this.TextBox1 = __ctrl; #line 14 "http://localhost/WebApplication22/WebForm16.aspx" __ctrl.ID = "TextBox1"; #line default #line 14 "http://localhost/WebApplication22/WebForm16.aspx" ((System.Web.UI.IAttributeAccessor)(__ctrl)).SetAttribute("style", "Z-INDEX: 102; LEFT: 96px; POSITION: absolute; TOP: 93px"); #line default return __ctrl; }​
לעומתם HTMLControls מונדרים ללא כל פעולה נוספת של יצירת אובייקטים :
__parser.AddParsedSubObject(new System.Web.UI.LiteralControl("\r\n\t\t\t<INPUT style=\"Z-INDEX: 101; LEFT: 109px; POSITION: absolute; TOP: 143px\" typ" + "e=\"text\">\r\n\t\t\t"));​
אך אם ה HTMLControl מכיל את המאפין Runat=server אזי גם HTMLCOntrol יתבצע כאוביקט ולא חרונדר ישירות :
private System.Web.UI.Control __BuildControl__control2() { System.Web.UI.HtmlControls.HtmlInputText __ctrl; #line 13 "http://localhost/WebApplication22/WebForm16.aspx" __ctrl = new System.Web.UI.HtmlControls.HtmlInputText(); #line default this.__control2 = __ctrl; #line 13 "http://localhost/WebApplication22/WebForm16.aspx" ((System.Web.UI.IAttributeAccessor)(__ctrl)).SetAttribute("style", "Z-INDEX: 101; LEFT: 109px; POSITION: absolute; TOP: 143px"); #line default #line 13 "http://localhost/WebApplication22/WebForm16.aspx" ((System.Web.UI.IAttributeAccessor)(__ctrl)).SetAttribute("type", "text"); #line default return __ctrl; }​
 
למעלה